コード例 #1
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Attempt to login
  *   <li>Have the login fail with a status code of 404
  *   <li>Check to make sure the callback is called
  *   <li>Check to make sure the events handler is called
  *   <li>Make sure the frontend failure handler is called
  * </ol>
  */
 @Test
 public void testLoginAsync_404_failure() {
   String testUser = "******"; // $NON-NLS-1$
   String testPassword = "******"; // $NON-NLS-1$
   String testProfile = "testprofile"; // $NON-NLS-1$
   frontend.initLoggedInUser(new DbUser(), testPassword);
   when(mockAsyncQuery.isHandleFailure()).thenReturn(Boolean.TRUE);
   frontend.loginAsync(testUser, testPassword, testProfile, false, mockAsyncQuery);
   verify(mockService)
       .login(
           eq(testUser),
           eq(testPassword),
           eq(testProfile),
           eq(VdcActionType.LoginUser),
           callbackAction.capture());
   StatusCodeException exception =
       new StatusCodeException(HttpServletResponse.SC_NOT_FOUND, "404 status code"); // $NON-NLS-1$
   callbackAction.getValue().onFailure(exception);
   verify(mockEventsHandler).runQueryFailed(null);
   verify(mockFrontendFailureEvent).raise(eq(Frontend.class), (EventArgs) any());
   assertNull("Logged in user should be null", frontend.getLoggedInUser()); // $NON-NLS-1$
   verify(mockAsyncCallback).onSuccess(any(), any());
 }
コード例 #2
0
 /**
  * Run the following test case.
  *
  * <ol>
  *   <li>Attempt to login
  *   <li>Have the login fail
  *   <li>Check to make sure the callback is called
  *   <li>Check to make sure the events handler is called
  *   <li>Make sure the frontend failure handler is not called
  * </ol>
  */
 @Test
 public void testLoginAsync_login_failure() {
   Object model = new Object();
   when(mockAsyncQuery.getModel()).thenReturn(model);
   String testUser = "******"; // $NON-NLS-1$
   String testPassword = "******"; // $NON-NLS-1$
   String testProfile = "testprofile"; // $NON-NLS-1$
   frontend.initLoggedInUser(new DbUser(), testPassword);
   when(mockAsyncQuery.isHandleFailure()).thenReturn(Boolean.TRUE);
   frontend.loginAsync(testUser, testPassword, testProfile, false, mockAsyncQuery);
   verify(mockService)
       .login(
           eq(testUser),
           eq(testPassword),
           eq(testProfile),
           eq(VdcActionType.LoginUser),
           callbackAction.capture());
   VdcReturnValueBase returnValue = new VdcReturnValueBase();
   returnValue.setSucceeded(false); // Yes I know this is the default, just to be sure.
   callbackAction.getValue().onSuccess(returnValue);
   verify(mockAsyncCallback).onSuccess(model, returnValue);
   verify(mockLoginHandler, never()).onLoginSuccess(testUser, testPassword, testProfile);
   verify(mockFrontendFailureEvent, never()).raise(eq(Frontend.class), (EventArgs) any());
 }