Alexander Wels has uploaded a new change for review.

Change subject: userportal,webadmin: Frontend refactor[WIP]
......................................................................

userportal,webadmin: Frontend refactor[WIP]

- Minor refactor to allow unit testing.

Change-Id: I3dae5a455ad16660b97cddafba53b53d3b4196f1
Signed-off-by: Alexander Wels <aw...@redhat.com>
---
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AsyncQuery.java
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/Frontend.java
A 
frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendTest.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/ConfigureLocalStorageModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/SanStorageModelBase.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageModelBehavior.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/AbstractDiskModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java
9 files changed, 475 insertions(+), 44 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/99/15399/1

diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AsyncQuery.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AsyncQuery.java
index 8bdc323..3ad6374 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AsyncQuery.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AsyncQuery.java
@@ -94,5 +94,4 @@
     public IAsyncConverter getConverter() {
         return converterCallback;
     }
-
 }
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/Frontend.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/Frontend.java
index 2bf3e39..9887301 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/Frontend.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/Frontend.java
@@ -20,6 +20,7 @@
 import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.core.common.users.VdcUser;
 import org.ovirt.engine.ui.frontend.gwtservices.GenericApiGWTServiceAsync;
+import org.ovirt.engine.ui.uicompat.Constants;
 import org.ovirt.engine.ui.uicompat.ConstantsManager;
 import org.ovirt.engine.ui.uicompat.Event;
 import org.ovirt.engine.ui.uicompat.EventArgs;
@@ -80,13 +81,12 @@
     private static IFrontendEventsHandler eventsHandler;
     private static FrontendLoginHandler loginHandler;
     private static VdcUser loggedUser;
-    private static ErrorTranslator canDoActionErrorsTranslator =
-            new ErrorTranslator((AppErrors) GWT.create(AppErrors.class));
-    private static ErrorTranslator vdsmErrorsTranslator =
-            new ErrorTranslator((VdsmErrors) GWT.create(VdsmErrors.class));
+    private static ErrorTranslator canDoActionErrorsTranslator = null;
+    private static ErrorTranslator vdsmErrorsTranslator = null;
 
-    private static final Map<String, QueryWrapper> currentRequests = new 
HashMap<String, Frontend.QueryWrapper>();
-    private static final Map<String, QueryWrapper> pendingRequests = new 
HashMap<String, Frontend.QueryWrapper>();
+    static Constants constants = null;
+    static final Map<String, QueryWrapper> currentRequests = new 
HashMap<String, Frontend.QueryWrapper>();
+    static final Map<String, QueryWrapper> pendingRequests = new 
HashMap<String, Frontend.QueryWrapper>();
 
     private static VdcQueryType[] subscribedQueryTypes;
 
@@ -98,7 +98,7 @@
 
     private static Event frontendFailureEvent = new Event("FrontendFailure", 
Frontend.class); //$NON-NLS-1$
 
-    private static Event frontendNotLoggedInEvent = new Event("NotLoggedIn", 
Frontend.class); //$NON-NLS-1$
+    static Event frontendNotLoggedInEvent = new Event("NotLoggedIn", 
Frontend.class); //$NON-NLS-1$
 
     /**
      * empty callback.
@@ -130,12 +130,19 @@
     }
 
     public static ErrorTranslator getAppErrorsTranslator() {
+        if (canDoActionErrorsTranslator == null) {
+            setAppErrorsTranslator(new ErrorTranslator((AppErrors) 
GWT.create(AppErrors.class)));
+        }
         return canDoActionErrorsTranslator;
+    }
+
+    protected static void setAppErrorsTranslator(ErrorTranslator translator) {
+        canDoActionErrorsTranslator = translator;
     }
 
     private static void translateErrors(List<VdcReturnValueBase> errors) {
         for (VdcReturnValueBase retVal : errors) {
-            
retVal.setCanDoActionMessages(canDoActionErrorsTranslator.translateErrorText(retVal.getCanDoActionMessages()));
+            
retVal.setCanDoActionMessages(getAppErrorsTranslator().translateErrorText(retVal.getCanDoActionMessages()));
         }
     }
 
@@ -146,15 +153,21 @@
     private static void failureEventHandler(Throwable caught) {
         String errorMessage;
         if (caught instanceof StatusCodeException) {
-            errorMessage = 
ConstantsManager.getInstance().getConstants().requestToServerFailedWithCode() + 
": " //$NON-NLS-1$
+            errorMessage = getConstants().requestToServerFailedWithCode() + ": 
" //$NON-NLS-1$
                     + ((StatusCodeException) caught).getStatusCode();
-        }
-        else {
+        } else {
             errorMessage =
-                    
ConstantsManager.getInstance().getConstants().requestToServerFailed()
+                    getConstants().requestToServerFailed()
                             + ": " + caught.getLocalizedMessage(); 
//$NON-NLS-1$
         }
         failureEventHandler(errorMessage);
+    }
+
+    static Constants getConstants() {
+        if (constants == null) {
+            constants = ConstantsManager.getInstance().getConstants();
+        }
+        return constants;
     }
 
     private static void failureEventHandler(String description, String 
errorMessage) {
@@ -190,6 +203,14 @@
     public static void RunQuery(final VdcQueryType queryType,
             final VdcQueryParametersBase parameters,
             final AsyncQuery callback) {
+        final GenericApiGWTServiceAsync service = 
GenericApiGWTServiceAsync.Util.getInstance();
+        RunQuery(queryType, parameters, service, callback);
+    }
+
+    protected static void RunQuery(final VdcQueryType queryType,
+            final VdcQueryParametersBase parameters,
+            final GenericApiGWTServiceAsync service,
+            final AsyncQuery callback) {
         final QueryWrapper queryWrapper = new QueryWrapper(queryType, 
parameters, callback);
         final boolean isHandleSequentialQueries = 
isHandleSequentialQueries(queryWrapper);
         if (isHandleSequentialQueries) {
@@ -205,7 +226,6 @@
         dumpQueryDetails(queryType, parameters);
         logger.finer("Frontend: Invoking async runQuery."); //$NON-NLS-1$
         raiseQueryStartedEvent(queryType, callback.getContext());
-        final GenericApiGWTServiceAsync service = 
GenericApiGWTServiceAsync.Util.getInstance();
         service.RunQuery(queryType, parameters, new 
AsyncCallback<VdcQueryReturnValue>() {
             @Override
             public void onFailure(final Throwable caught) {
@@ -217,7 +237,7 @@
                     getEventsHandler().runQueryFailed(null);
                     failureEventHandler(caught);
                     if (callback.isHandleFailure()) {
-                        callback.asyncCallback.onSuccess(callback.getModel(), 
null);
+                        callback.getDel().onSuccess(callback.getModel(), null);
                     }
                     raiseQueryCompleteEvent(queryType, callback.getContext());
                 } finally {
@@ -269,7 +289,7 @@
                 QueryWrapper wrapper = pendingRequests.get(key);
                 if (wrapper != null) {
                     pendingRequests.remove(queryWrapper.getKey());
-                    RunQuery(wrapper.getQueryType(), wrapper.getParameters(), 
wrapper.getCallback());
+                    RunQuery(wrapper.getQueryType(), wrapper.getParameters(), 
service, wrapper.getCallback());
                 }
             }
 
@@ -329,8 +349,7 @@
                     if (callback.getConverter() != null) {
                         callback.getDel().onSuccess(callback.getModel(),
                                 
callback.getConverter().Convert(result.getReturnValue(), callback));
-                    }
-                    else {
+                    } else {
                         callback.getDel().onSuccess(callback.getModel(), 
result);
                     }
                 }
@@ -816,13 +835,24 @@
         if (getEventsHandler() != null) {
             // The VdcFault error property takes precedence, if it's null we 
try to translate the message property
             String translatedMessage =
-                    
vdsmErrorsTranslator.TranslateErrorTextSingle(fault.getError() == null ? 
fault.getMessage()
+                    
getVdsmErrorsTranslator().TranslateErrorTextSingle(fault.getError() == null ? 
fault.getMessage()
                             : fault.getError().toString());
             fault.setMessage(translatedMessage);
             getEventsHandler().runActionExecutionFailed(actionType, fault);
         }
     }
 
+    public static ErrorTranslator getVdsmErrorsTranslator() {
+        if (vdsmErrorsTranslator == null) {
+            setVdsmErrorsTranslator(new ErrorTranslator((VdsmErrors) 
GWT.create(VdsmErrors.class)));
+        }
+        return vdsmErrorsTranslator;
+    }
+
+    protected static void setVdsmErrorsTranslator(ErrorTranslator translator) {
+        vdsmErrorsTranslator = translator;
+    }
+
     public static void Subscribe(VdcQueryType[] queryTypes)
     {
         subscribedQueryTypes = queryTypes;
diff --git 
a/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendTest.java
 
b/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendTest.java
new file mode 100644
index 0000000..513faee
--- /dev/null
+++ 
b/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendTest.java
@@ -0,0 +1,415 @@
+package org.ovirt.engine.ui.frontend;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.ovirt.engine.core.common.interfaces.SearchType;
+import org.ovirt.engine.core.common.queries.SearchParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryParametersBase;
+import org.ovirt.engine.core.common.queries.VdcQueryReturnValue;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.ui.frontend.gwtservices.GenericApiGWTServiceAsync;
+import org.ovirt.engine.ui.uicompat.Constants;
+import org.ovirt.engine.ui.uicompat.Event;
+import org.ovirt.engine.ui.uicompat.EventArgs;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.rpc.StatusCodeException;
+
+@RunWith(MockitoJUnitRunner.class)
+public class FrontendTest {
+
+    @Mock
+    GenericApiGWTServiceAsync mockService;
+    @Mock
+    ErrorTranslator mockVdsmErrorsTranslator;
+    @Mock
+    ErrorTranslator mockCanDoActionErrorsTranslator;
+    @Mock
+    Event queryCompleteEvent;
+    @Mock
+    Event queryStartEvent;
+    @Mock
+    Event frontendNotLoggedInEvent;
+    @Mock
+    IFrontendEventsHandler mockEventsHandler;
+    @Mock
+    Constants mockConstants;
+    @Mock
+    AsyncQuery mockAsyncQuery;
+    @Mock
+    INewAsyncCallback mockAsyncCallback;
+    @Mock
+    IAsyncConverter mockConverter;
+    @Captor
+    ArgumentCaptor<AsyncCallback<VdcQueryReturnValue>> callback;
+
+    @Before
+    public void setUp() throws Exception {
+        Frontend.setAppErrorsTranslator(mockCanDoActionErrorsTranslator);
+        Frontend.setVdsmErrorsTranslator(mockVdsmErrorsTranslator);
+        Frontend.QueryCompleteEvent = queryCompleteEvent;
+        Frontend.QueryStartedEvent = queryStartEvent;
+        Frontend.frontendNotLoggedInEvent = frontendNotLoggedInEvent;
+        Frontend.Subscribe(new VdcQueryType[] {VdcQueryType.Search });
+        Frontend.setEventsHandler(mockEventsHandler);
+        Frontend.constants = mockConstants;
+        when(mockAsyncQuery.getContext()).thenReturn("test"); //$NON-NLS-1$
+        when(mockAsyncQuery.getDel()).thenReturn(mockAsyncCallback);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        // Make sure that the query start and end have been called at least 
once.
+        // Some of the tests might call it more than once.
+        verify(queryStartEvent, atLeastOnce()).raise(Frontend.class, 
EventArgs.Empty);
+        verify(queryCompleteEvent, atLeastOnce()).raise(Frontend.class, 
EventArgs.Empty);
+        //Make sure the context is correct
+        assertEquals("Context should be 'test'", Frontend.getCurrentContext(), 
"test"); //$NON-NLS-1$ //$NON-NLS-2$
+        //Make sure that the pending requests and current requests are empty.
+        assertEquals("There should be no pending requests", 0, 
Frontend.pendingRequests.size());
+        assertEquals("There should be no current requests", 0, 
Frontend.currentRequests.size());
+    }
+
+    /*
+     * TODO, make sure that this test succeeds instead of fails. The test is 
correct, the code is broken.
+     * The code should call the queryCompleteEvent in case of an 'ignored' 
failure, and it doesn't.
+     */
+    /**
+     * Run the following test case.
+     * <ol>
+     *   <li>Run a search query, with *win* as the parameter, searching for 
VMs</li>
+     *   <li>The callback is NOT marked to handle failures</li>
+     *   <li>Force a special failure with an HTTP status code = 0, this is an 
ignored failure</li>
+     *   <li>Check to make sure the appropriate query start and query complete 
events are fired</li>
+     * </ol>
+     */
+    @Ignore
+    @Test
+    public void testRunQuery_ignored_failure() {
+        VdcQueryParametersBase testParameters = new SearchParameters("*win*", 
SearchType.VM); //$NON-NLS-1$
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        verify(mockService).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        StatusCodeException exception = new StatusCodeException(0, "0 status 
code"); //$NON-NLS-1$
+        // Call the failure handler.
+        callback.getValue().onFailure(exception);
+    }
+
+    /**
+     * Run the following test case.
+     * <ol>
+     *   <li>Run a search query, with *win* as the parameter, searching for 
VMs</li>
+     *   <li>The callback is NOT marked to handle failures</li>
+     *   <li>Force a failure with an HTTP status code = 404 (file not 
found)</li>
+     *   <li>Check to make sure the appropriate query start and query complete 
events are fired</li>
+     * </ol>
+     */
+    @Test
+    public void testRunQuery_failure_404() {
+        VdcQueryParametersBase testParameters = new SearchParameters("*win*", 
SearchType.VM); //$NON-NLS-1$
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        verify(mockService).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        StatusCodeException exception = new 
StatusCodeException(HttpServletResponse.SC_NOT_FOUND,
+                "404 status code"); //$NON-NLS-1$
+        // Call the failure handler.
+        callback.getValue().onFailure(exception);
+        verify(mockEventsHandler).runQueryFailed(null);
+    }
+
+    /**
+     * Run the following test case.
+     * <ol>
+     *   <li>Run a search query, with *win* as the parameter, searching for 
VMs</li>
+     *   <li>The callback is marked to handle failures, make sure the callback 
failure handler is called</li>
+     *   <li>Force a failure with an HTTP status code = 404 (file not 
found)</li>
+     *   <li>Check to make sure the appropriate query start and query complete 
events are fired</li>
+     * </ol>
+     */
+    @Test
+    public void testRunQuery_failure_404_callback() {
+        Object mockModel = new Object();
+        when(mockAsyncQuery.isHandleFailure()).thenReturn(true);
+        when(mockAsyncQuery.getModel()).thenReturn(mockModel);
+        VdcQueryParametersBase testParameters = new SearchParameters("*win*", 
SearchType.VM); //$NON-NLS-1$
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        verify(mockService).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        StatusCodeException exception = new 
StatusCodeException(HttpServletResponse.SC_NOT_FOUND,
+                "404 status code"); //$NON-NLS-1$
+        // Call the failure handler.
+        callback.getValue().onFailure(exception);
+        verify(mockAsyncCallback).onSuccess(mockModel, null);
+        verify(mockEventsHandler).runQueryFailed(null);
+    }
+
+    /**
+     * Run the following test case.
+     * <ol>
+     *   <li>Run a search query, with *win* as the parameter, searching for 
VMs</li>
+     *   <li>Immediately, before returning a failure result, call the same run 
query again</li>
+     *   <li>The callback is NOT marked to handle failures</li>
+     *   <li>Force a failure with an HTTP status code = 404 (file not 
found)</li>
+     *   <li>Check to make sure both queries are called sequentially</li>
+     *   <li>Check to make sure the appropriate query start and query complete 
events are fired</li>
+     * </ol>
+     */
+    @Test
+    public void testRunQuery_failure_404_with_pending() {
+        VdcQueryParametersBase testParameters = new SearchParameters("*win*", 
SearchType.VM); //$NON-NLS-1$
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        // Verify that only one request is executed, until the first one is 
complete.
+        verify(mockService, times(1)).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        // Now finish the first request.
+        StatusCodeException exception = new 
StatusCodeException(HttpServletResponse.SC_NOT_FOUND,
+                "404 status code"); //$NON-NLS-1$
+        // Call the failure handler.
+        callback.getValue().onFailure(exception);
+        // Verify that the second one is called since the first one is now 
complete.
+        verify(mockService, times(2)).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        // Call the failure handler for the second request.
+        callback.getValue().onFailure(exception);
+        verify(mockEventsHandler, atLeastOnce()).runQueryFailed(null);
+    }
+
+    /**
+     * Run the following test case.
+     * <ol>
+     *   <li>Run a search query, with *win* as the parameter, searching for 
VMs</li>
+     *   <li>Immediately, before returning a failure result, call the same run 
query again, total 3 times</li>
+     *   <li>The callback is NOT marked to handle failures</li>
+     *   <li>Force a failure with an HTTP status code = 404 (file not 
found)</li>
+     *   <li>Check to make sure both queries are called sequentially</li>
+     *   <li>Check to make sure the appropriate query start and query complete 
events are fired</li>
+     * </ol>
+     */
+    @Test
+    public void testRunQuery_failure_404_with_pending_3times() {
+        VdcQueryParametersBase testParameters = new SearchParameters("*win*", 
SearchType.VM); //$NON-NLS-1$
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        // Verify that only one request is executed, until the first one is 
complete.
+        verify(mockService, times(1)).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        // Now finish the first request.
+        StatusCodeException exception = new 
StatusCodeException(HttpServletResponse.SC_NOT_FOUND,
+                "404 status code"); //$NON-NLS-1$
+        // Call the failure handler.
+        callback.getValue().onFailure(exception);
+        // Verify that the second one is called since the first one is now 
complete.
+        verify(mockService, times(2)).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        // Call the failure handler for the second request.
+        callback.getValue().onFailure(exception);
+        verify(mockEventsHandler, atLeastOnce()).runQueryFailed(null);
+    }
+
+    /**
+     * Run the following test case.
+     * <ol>
+     *   <li>Run a search query, with *win* as the parameter, searching for 
VMs</li>
+     *   <li>Immediately, before returning a failure result, call the same run 
query again, total 5 times</li>
+     *   <li>The callback is NOT marked to handle failures</li>
+     *   <li>Force a failure with an HTTP status code = 404 (file not 
found)</li>
+     *   <li>Check to make sure both queries are called sequentially</li>
+     *   <li>Check to make sure the appropriate query start and query complete 
events are fired</li>
+     * </ol>
+     */
+    @Test
+    public void testRunQuery_failure_404_with_pending_5times() {
+        VdcQueryParametersBase testParameters = new SearchParameters("*win*", 
SearchType.VM); //$NON-NLS-1$
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        // Verify that only one request is executed, until the first one is 
complete.
+        verify(mockService, times(1)).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        // Now finish the first request.
+        StatusCodeException exception = new 
StatusCodeException(HttpServletResponse.SC_NOT_FOUND,
+                "404 status code"); //$NON-NLS-1$
+        // Call the failure handler.
+        callback.getValue().onFailure(exception);
+        // Verify that the second one is called since the first one is now 
complete.
+        verify(mockService, times(2)).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        // Call the failure handler for the second request.
+        callback.getValue().onFailure(exception);
+        verify(mockEventsHandler, atLeastOnce()).runQueryFailed(null);
+    }
+
+    /**
+     * Run the following test case.
+     * <ol>
+     *   <li>Run a search query, with *win* as the parameter, searching for 
VMs</li>
+     *   <li>The callback is NOT marked to handle failures</li>
+     *   <li>The failure is NOT, a not logged in failure</li>
+     *   <li>Return success, but the success status is !succeeded (business 
logic failure/not logged in)</li>
+     *   <li>Check to make sure the appropriate query start and query complete 
events are fired</li>
+     * </ol>
+     */
+    @Test
+    public void 
testRunQuery_success_not_succeeded_noeventshandler_nocallbackhandler() {
+        VdcQueryParametersBase testParameters = new SearchParameters("*win*", 
SearchType.VM); //$NON-NLS-1$
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        verify(mockService).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        VdcQueryReturnValue mockReturnValue = new VdcQueryReturnValue();
+        mockReturnValue.setExceptionString("Fake failure for test"); 
//$NON-NLS-1$
+        //Return value set to failure
+        mockReturnValue.setSucceeded(false);
+        callback.getValue().onSuccess(mockReturnValue);
+        //Make sure the not logged in event is never called, as the failure is 
not a USER_IS_NOT_LOGGED_IN
+        verify(frontendNotLoggedInEvent, never()).raise(Frontend.class, 
EventArgs.Empty);
+    }
+
+    /**
+     * Run the following test case.
+     * <ol>
+     *   <li>Run a search query, with *win* as the parameter, searching for 
VMs</li>
+     *   <li>The callback is NOT marked to handle failures</li>
+     *   <li>The failure is a not logged in failure</li>
+     *   <li>Return success, but the success status is !succeeded (business 
logic failure/not logged in)</li>
+     *   <li>Check to make sure the appropriate query start and query complete 
events are fired</li>
+     * </ol>
+     */
+    @Test
+    public void 
testRunQuery_success_not_succeeded_eventshandler_nocallbackhandler() {
+        VdcQueryParametersBase testParameters = new SearchParameters("*win*", 
SearchType.VM); //$NON-NLS-1$
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        verify(mockService).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        VdcQueryReturnValue mockReturnValue = new VdcQueryReturnValue();
+        mockReturnValue.setExceptionString("USER_IS_NOT_LOGGED_IN"); 
//$NON-NLS-1$
+        //Return value set to failure
+        mockReturnValue.setSucceeded(false);
+        callback.getValue().onSuccess(mockReturnValue);
+        //Make sure the not logged in event is called
+        verify(frontendNotLoggedInEvent).raise(Frontend.class, 
EventArgs.Empty);
+    }
+
+    /**
+     * Run the following test case.
+     * <ol>
+     *   <li>Run a search query, with *win* as the parameter, searching for 
VMs</li>
+     *   <li>The callback is marked to handle failures</li>
+     *   <li>The failure is a not logged in failure</li>
+     *   <li>Return success, but the success status is !succeeded (business 
logic failure/not logged in)</li>
+     *   <li>Make sure the proper model is passed to the callback failure 
handler</li>
+     *   <li>Check to make sure the appropriate query start and query complete 
events are fired</li>
+     * </ol>
+     */
+    @Test
+    public void 
testRunQuery_success_not_succeeded_eventshandler_callbackhandler() {
+        Object mockModel = new Object();
+        when(mockAsyncQuery.isHandleFailure()).thenReturn(true);
+        when(mockAsyncQuery.getModel()).thenReturn(mockModel);
+        VdcQueryParametersBase testParameters = new SearchParameters("*win*", 
SearchType.VM); //$NON-NLS-1$
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        verify(mockService).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        VdcQueryReturnValue mockReturnValue = new VdcQueryReturnValue();
+        mockReturnValue.setExceptionString("USER_IS_NOT_LOGGED_IN"); 
//$NON-NLS-1$
+        //Return value set to failure
+        mockReturnValue.setSucceeded(false);
+        callback.getValue().onSuccess(mockReturnValue);
+        //Make sure the not logged in event is called
+        verify(frontendNotLoggedInEvent).raise(Frontend.class, 
EventArgs.Empty);
+        verify(mockAsyncCallback).onSuccess(mockModel, mockReturnValue);
+    }
+
+    /**
+     * Run the following test case.
+     * <ol>
+     *   <li>Run a search query, with *win* as the parameter, searching for 
VMs</li>
+     *   <li>Return success, the success status is succeeded</li>
+     *   <li>No success converter defined</li>
+     *   <li>Check to make sure the appropriate query start and query complete 
events are fired</li>
+     * </ol>
+     */
+    @Test
+    public void testRunQuery_success_succeeded_eventshandler_noconverter() {
+        Object mockModel = new Object();
+        when(mockAsyncQuery.getModel()).thenReturn(mockModel);
+        VdcQueryParametersBase testParameters = new SearchParameters("*win*", 
SearchType.VM); //$NON-NLS-1$
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        verify(mockService).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        VdcQueryReturnValue mockReturnValue = new VdcQueryReturnValue();
+        mockReturnValue.setSucceeded(true);
+        callback.getValue().onSuccess(mockReturnValue);
+        verify(mockAsyncQuery).setOriginalReturnValue(mockReturnValue);
+        verify(mockAsyncCallback).onSuccess(mockModel, mockReturnValue);
+    }
+
+    /**
+     * Run the following test case.
+     * <ol>
+     *   <li>Run a search query, with *win* as the parameter, searching for 
VMs</li>
+     *   <li>Return success, the success status is succeeded</li>
+     *   <li>A success converter defined</li>
+     *   <li>Check that the converted value is returned to the callback</li>
+     *   <li>Check to make sure the appropriate query start and query complete 
events are fired</li>
+     * </ol>
+     */
+    @Test
+    public void testRunQuery_success_succeeded_eventshandler_converter() {
+        Object mockModel = new Object();
+        Object mockResultModel = new Object();
+        Object mockConvertedModel = new Object();
+        when(mockAsyncQuery.getModel()).thenReturn(mockModel);
+        when(mockAsyncQuery.getConverter()).thenReturn(mockConverter);
+        VdcQueryParametersBase testParameters = new SearchParameters("*win*", 
SearchType.VM); //$NON-NLS-1$
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        verify(mockService).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        VdcQueryReturnValue mockReturnValue = new VdcQueryReturnValue();
+        mockReturnValue.setReturnValue(mockResultModel);
+        mockReturnValue.setExceptionString("USER_IS_NOT_LOGGED_IN"); 
//$NON-NLS-1$
+        when(mockConverter.Convert(mockResultModel, 
mockAsyncQuery)).thenReturn(mockConvertedModel);
+        //Return value set to failure
+        mockReturnValue.setSucceeded(true);
+        callback.getValue().onSuccess(mockReturnValue);
+        verify(mockAsyncQuery).setOriginalReturnValue(mockReturnValue);
+        verify(mockAsyncCallback).onSuccess(mockModel, mockConvertedModel);
+    }
+
+    /**
+     * Run the following test case.
+     * <ol>
+     *   <li>Run a search query, with *win* as the parameter, searching for 
VMs</li>
+     *   <li>Immediately, before returning a result, call the same run query 
again</li>
+     *   <li>Return success, the success status is succeeded</li>
+     *   <li>No success converter defined</li>
+     *   <li>Make sure that the result callback is called (once normally, once 
pending)</li>
+     *   <li>Check to make sure the appropriate query start and query complete 
events are fired</li>
+     * </ol>
+     */
+    @Test
+    public void 
testRunQuery_success_succeeded_multiple_same_eventshandler_noconverter() {
+        Object mockModel = new Object();
+        when(mockAsyncQuery.getModel()).thenReturn(mockModel);
+        VdcQueryParametersBase testParameters = new SearchParameters("*win*", 
SearchType.VM); //$NON-NLS-1$
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        Frontend.RunQuery(VdcQueryType.Search, testParameters, mockService, 
mockAsyncQuery);
+        verify(mockService).RunQuery(eq(VdcQueryType.Search), 
eq(testParameters), callback.capture());
+        VdcQueryReturnValue mockReturnValue = new VdcQueryReturnValue();
+        mockReturnValue.setExceptionString("USER_IS_NOT_LOGGED_IN"); 
//$NON-NLS-1$
+        //Return value set to failure
+        mockReturnValue.setSucceeded(true);
+        callback.getValue().onSuccess(mockReturnValue);
+        verify(mockAsyncCallback).onSuccess(mockModel, mockReturnValue);
+        reset(mockAsyncCallback);
+        callback.getValue().onSuccess(mockReturnValue);
+        verify(mockAsyncCallback).onSuccess(mockModel, mockReturnValue);
+    }
+}
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/ConfigureLocalStorageModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/ConfigureLocalStorageModel.java
index a0392f2..6081e4a 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/ConfigureLocalStorageModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/ConfigureLocalStorageModel.java
@@ -167,11 +167,9 @@
 
         if (ev.matchesDefinition(ListModel.selectedItemChangedEventDefinition) 
&& sender == getDataCenter().getVersion()) {
             dataCenterVersion_SelectedItemChanged();
-        } else if (ev.matchesDefinition(Frontend.QueryStartedEventDefinition)
-                && StringHelper.stringsEqual(Frontend.getCurrentContext(), 
frontendHash)) {
+        } else if (ev.matchesDefinition(Frontend.QueryStartedEventDefinition)) 
{
             frontend_QueryStarted();
-        } else if (ev.matchesDefinition(Frontend.QueryCompleteEventDefinition)
-                && StringHelper.stringsEqual(Frontend.getCurrentContext(), 
frontendHash)) {
+        } else if 
(ev.matchesDefinition(Frontend.QueryCompleteEventDefinition)) {
             frontend_QueryComplete();
         }
     }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/SanStorageModelBase.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/SanStorageModelBase.java
index 7e57a48..11108d6 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/SanStorageModelBase.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/SanStorageModelBase.java
@@ -303,13 +303,11 @@
         {
             useUserAuth_EntityChanged(sender, args);
         }
-        else if (ev.matchesDefinition(Frontend.QueryStartedEventDefinition)
-                && StringHelper.stringsEqual(Frontend.getCurrentContext(), 
getHash()))
+        else if (ev.matchesDefinition(Frontend.QueryStartedEventDefinition))
         {
             frontend_QueryStarted();
         }
-        else if (ev.matchesDefinition(Frontend.QueryCompleteEventDefinition)
-                && StringHelper.stringsEqual(Frontend.getCurrentContext(), 
getHash()))
+        else if (ev.matchesDefinition(Frontend.QueryCompleteEventDefinition))
         {
             frontend_QueryComplete();
         }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageModel.java
index 94926e9..f57b4aa 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageModel.java
@@ -249,13 +249,11 @@
         {
             nfsStorageModel_PathChanged(sender, args);
         }
-        else if (ev.matchesDefinition(Frontend.QueryStartedEventDefinition)
-                && StringHelper.stringsEqual(Frontend.getCurrentContext(), 
getHash()))
+        else if (ev.matchesDefinition(Frontend.QueryStartedEventDefinition))
         {
             frontend_QueryStarted();
         }
-        else if (ev.matchesDefinition(Frontend.QueryCompleteEventDefinition)
-                && StringHelper.stringsEqual(Frontend.getCurrentContext(), 
getHash()))
+        else if (ev.matchesDefinition(Frontend.QueryCompleteEventDefinition))
         {
             frontend_QueryComplete();
         }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageModelBehavior.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageModelBehavior.java
index 334546a..67dddf2 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageModelBehavior.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/storage/StorageModelBehavior.java
@@ -5,7 +5,6 @@
 
 import org.ovirt.engine.core.common.businessentities.StoragePoolStatus;
 import org.ovirt.engine.core.common.businessentities.StoragePool;
-import org.ovirt.engine.core.compat.StringHelper;
 import org.ovirt.engine.ui.frontend.Frontend;
 import org.ovirt.engine.ui.uicommonweb.Linq;
 import org.ovirt.engine.ui.uicommonweb.models.Model;
@@ -94,13 +93,11 @@
     {
         super.eventRaised(ev, sender, args);
 
-        if (ev.matchesDefinition(Frontend.QueryStartedEventDefinition)
-                && StringHelper.stringsEqual(Frontend.getCurrentContext(), 
getHash()))
+        if (ev.matchesDefinition(Frontend.QueryStartedEventDefinition))
         {
             getModel().frontend_QueryStarted();
         }
-        else if (ev.matchesDefinition(Frontend.QueryCompleteEventDefinition)
-                && StringHelper.stringsEqual(Frontend.getCurrentContext(), 
getHash()))
+        else if (ev.matchesDefinition(Frontend.QueryCompleteEventDefinition))
         {
             getModel().frontend_QueryComplete();
         }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/AbstractDiskModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/AbstractDiskModel.java
index a8e7235..7649d56 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/AbstractDiskModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/AbstractDiskModel.java
@@ -739,13 +739,11 @@
         {
             datacenter_SelectedItemChanged();
         }
-        else if (ev.matchesDefinition(Frontend.QueryStartedEventDefinition)
-                && StringHelper.stringsEqual(Frontend.getCurrentContext(), 
getHash()))
+        else if (ev.matchesDefinition(Frontend.QueryStartedEventDefinition))
         {
             frontend_QueryStarted();
         }
-        else if (ev.matchesDefinition(Frontend.QueryCompleteEventDefinition)
-                && StringHelper.stringsEqual(Frontend.getCurrentContext(), 
getHash()))
+        else if (ev.matchesDefinition(Frontend.QueryCompleteEventDefinition))
         {
             frontend_QueryComplete();
         }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java
index c6fb9e5..68a8962 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/UnitVmModel.java
@@ -1258,13 +1258,11 @@
     {
         super.eventRaised(ev, sender, args);
 
-        if (ev.matchesDefinition(Frontend.QueryStartedEventDefinition)
-                && StringHelper.stringsEqual(Frontend.getCurrentContext(), 
getHash()))
+        if (ev.matchesDefinition(Frontend.QueryStartedEventDefinition))
         {
             frontend_QueryStarted();
         }
-        else if (ev.matchesDefinition(Frontend.QueryCompleteEventDefinition)
-                && StringHelper.stringsEqual(Frontend.getCurrentContext(), 
getHash()))
+        else if (ev.matchesDefinition(Frontend.QueryCompleteEventDefinition))
         {
             frontend_QueryComplete();
         }


--
To view, visit http://gerrit.ovirt.org/15399
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3dae5a455ad16660b97cddafba53b53d3b4196f1
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alexander Wels <aw...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to