mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-04 01:59:35 +00:00
introduced AbstractEntryPoint in SSE, adding Selenium AJAX call support generally
This commit is contained in:
1 parent
95d1c9114d
commit
4ba062efbc
8 files changed
+95
-30
No files matched your search
+2
-25
@@ -1,13 +1,10 @@
|
||||
package com.sap.sailing.gwt.ui.client;
|
||||
|
||||
import com.google.gwt.core.client.EntryPoint;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.debug.client.DebugInfo;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.logical.shared.AttachEvent;
|
||||
import com.google.gwt.event.logical.shared.AttachEvent.Handler;
|
||||
import com.google.gwt.resources.client.TextResource;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.ServiceDefTarget;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
@@ -18,20 +15,15 @@ import com.google.gwt.user.client.ui.RootPanel;
|
||||
import com.google.gwt.user.client.ui.TabLayoutPanel;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
import com.sap.sse.gwt.client.EntryPointHelper;
|
||||
import com.sap.sse.gwt.client.async.MarkedAsyncCallback;
|
||||
import com.sap.sse.gwt.client.async.PendingAjaxCallMarker;
|
||||
import com.sap.sse.gwt.client.useragent.UserAgentDetails;
|
||||
import com.sap.sse.gwt.shared.DebugConstants;
|
||||
import com.sap.sse.security.ui.client.UserService;
|
||||
import com.sap.sse.security.ui.shared.UserManagementService;
|
||||
import com.sap.sse.security.ui.shared.UserManagementServiceAsync;
|
||||
|
||||
public abstract class AbstractEntryPoint implements EntryPoint, ErrorReporter, WindowSizeDetector {
|
||||
public abstract class AbstractEntryPoint extends com.sap.sse.gwt.client.AbstractEntryPoint implements ErrorReporter, WindowSizeDetector {
|
||||
private DialogBox errorDialogBox;
|
||||
private HTML serverResponseLabel;
|
||||
private Button dialogCloseButton;
|
||||
protected StringMessages stringMessages;
|
||||
protected UserAgentDetails userAgent;
|
||||
protected Label persistentAlertLabel;
|
||||
private UserService userService;
|
||||
private UserManagementServiceAsync userManagementService;
|
||||
@@ -43,28 +35,13 @@ public abstract class AbstractEntryPoint implements EntryPoint, ErrorReporter, W
|
||||
private static final String SERVER_ERROR = "An error occurred while " //$NON-NLS-1$
|
||||
+ "attempting to contact the server. Please check your network " + "connection and try again."; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
@Override
|
||||
public final void onModuleLoad() {
|
||||
if (DebugInfo.isDebugIdEnabled()) {
|
||||
PendingAjaxCallBundle bundle = GWT.create(PendingAjaxCallBundle.class);
|
||||
TextResource script = bundle.ajaxSemaphoreJS();
|
||||
JavaScriptInjector.inject(script.getText());
|
||||
DebugInfo.setDebugIdAttribute(DebugConstants.DEBUG_ID_ATTRIBUTE, false);
|
||||
DebugInfo.setDebugIdPrefix(DebugConstants.DEBUG_ID_PREFIX);
|
||||
}
|
||||
doOnModuleLoad();
|
||||
if (DebugInfo.isDebugIdEnabled()) {
|
||||
PendingAjaxCallMarker.decrementPendingAjaxCalls(MarkedAsyncCallback.CATEGORY_GLOBAL);
|
||||
}
|
||||
}
|
||||
|
||||
protected void doOnModuleLoad() {
|
||||
super.doOnModuleLoad();
|
||||
userManagementService = GWT.create(UserManagementService.class);
|
||||
EntryPointHelper.registerASyncService((ServiceDefTarget) userManagementService, com.sap.sse.security.ui.client.RemoteServiceMappingConstants.userManagementServiceRemotePath);
|
||||
userService = new UserService(userManagementService);
|
||||
stringMessages = GWT.create(StringMessages.class);
|
||||
errorDialogBox = createErrorDialog(); /* TODO: Make this more generic (e.g. make it support all kinds of messages) */
|
||||
userAgent = new UserAgentDetails(Window.Navigator.getUserAgent());
|
||||
persistentAlertLabel = new Label("");
|
||||
persistentAlertLabel.setStyleName("global-alert-message");
|
||||
}
|
||||
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
package com.sap.sailing.gwt.ui.client;
|
||||
|
||||
import com.google.gwt.dom.client.Document;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.HeadElement;
|
||||
import com.google.gwt.dom.client.NodeList;
|
||||
import com.google.gwt.dom.client.ScriptElement;
|
||||
|
||||
/**
|
||||
* <p>Utility class to inject JavaScript in the default document.</p>
|
||||
*
|
||||
* @author
|
||||
* D049941
|
||||
*/
|
||||
public class JavaScriptInjector {
|
||||
private static HeadElement head;
|
||||
|
||||
/**
|
||||
* <p>Injects the given JavaScript code in the head of the default document. To inject the code a script element is
|
||||
* created and appended to the head element of the document.</p>
|
||||
*
|
||||
* @param javascript
|
||||
* The JavaScript code to inject.
|
||||
*/
|
||||
public static void inject(String javascript) {
|
||||
HeadElement head = getHead();
|
||||
ScriptElement element = createScriptElement();
|
||||
element.setText(javascript);
|
||||
head.appendChild(element);
|
||||
}
|
||||
|
||||
private static ScriptElement createScriptElement() {
|
||||
Document document = Document.get();
|
||||
ScriptElement script = document.createScriptElement();
|
||||
script.setAttribute("type", "text/javascript"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
return script;
|
||||
}
|
||||
|
||||
private static HeadElement getHead() {
|
||||
if (JavaScriptInjector.head == null) {
|
||||
Document document = Document.get();
|
||||
NodeList<Element> nodes = document.getElementsByTagName("head"); //$NON-NLS-1$
|
||||
Element element = nodes.getItem(0);
|
||||
assert element != null : "HTML Head element required"; //$NON-NLS-1$
|
||||
HeadElement head = HeadElement.as(element);
|
||||
JavaScriptInjector.head = head;
|
||||
}
|
||||
|
||||
return JavaScriptInjector.head;
|
||||
}
|
||||
|
||||
private JavaScriptInjector() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.sap.sailing.gwt.ui.client;
|
||||
|
||||
import com.google.gwt.resources.client.ClientBundle;
|
||||
import com.google.gwt.resources.client.TextResource;
|
||||
|
||||
/**
|
||||
* <p>The client bundle for the resource "ajax-semaphore.js" which is needed for the execution of UI tests.</p>
|
||||
*
|
||||
* @author
|
||||
* D049941
|
||||
*/
|
||||
public interface PendingAjaxCallBundle extends ClientBundle {
|
||||
/**
|
||||
* <p>Returns the JavaScript for the counter of pending Ajax requests. The counter is used in UI tests to be able
|
||||
* to tell exactly when an asynchronous request has finished.</p>
|
||||
*
|
||||
* @return
|
||||
* The JavaScript for the counter of pending Ajax requests.
|
||||
*/
|
||||
@Source("ajax-semaphore.js")
|
||||
TextResource ajaxSemaphoreJS();
|
||||
}
|
||||
-85
@@ -1,85 +0,0 @@
|
||||
/**
|
||||
* <p>JavaScript counter for pending Ajax requests. Since GWT application are heavily AJAX driven one of the challenges
|
||||
* in performing UI tests is to be able to tell when your application is in a state you expect. In simple cases you
|
||||
* can wait until a loading animation disappears or until a well known element has changed the state (e.g. visibility
|
||||
* or something else). However, since things are usually not that simple, especially in the context of GWT, it is more
|
||||
* stable if we are able to tell exactly when an asynchronous request has finished. For this reason we use the counter
|
||||
* for pending request which is incremented if an asynchronous callback is created and decremented if the callback
|
||||
* completes. With this counter a test which triggers a request (which can cause additional request) can wait until
|
||||
* the counter reaches 0 again.</p>
|
||||
*
|
||||
* @author
|
||||
* D049941
|
||||
*/
|
||||
var PENDING_AJAX_CALLS = PENDING_AJAX_CALLS || function() {
|
||||
/* Private variable bound through closure which holds the categories of AJAX requests. The counter for the global
|
||||
* category (empty string) is initialized to be 1. This is important because the GWT bootstrap process in itself can
|
||||
* take a bit of time. So, at a minimum we have to wait until the module is fully loaded. Otherwise, we will get the
|
||||
* occasional timing/synchronization failure during test runs.
|
||||
*/
|
||||
var categories = {
|
||||
"" : {
|
||||
pendingCalls : 1,
|
||||
finishedCalls : 0
|
||||
}
|
||||
};
|
||||
|
||||
function getCategory(category) {
|
||||
if(!(category in categories)) {
|
||||
categories[category] = {
|
||||
pendingCalls : 0,
|
||||
finishedCalls : 0
|
||||
}
|
||||
}
|
||||
|
||||
return categories[category];
|
||||
};
|
||||
|
||||
return {
|
||||
/**
|
||||
* <p></p>
|
||||
*
|
||||
* @param {string} category
|
||||
* The category of pending Ajax requests.
|
||||
* @returns {int}
|
||||
* The number of pending Ajax requests.
|
||||
*/
|
||||
numberOfPendingCalls : function(category) {
|
||||
return getCategory(category).pendingCalls;
|
||||
},
|
||||
|
||||
/**
|
||||
* <p></p>
|
||||
*
|
||||
* @param {string} category
|
||||
* The category of finished Ajax requests.
|
||||
* @returns {int}
|
||||
* The number of finished Ajax requests.
|
||||
*/
|
||||
numberOfFinishedCalls : function(category) {
|
||||
return getCategory(category).finishedCalls;
|
||||
},
|
||||
|
||||
/**
|
||||
* <p>Decrements the counter by 1. This method should be called if an Ajax request is created.</p>
|
||||
*
|
||||
* @param {string} category
|
||||
* The category of the Ajax request.
|
||||
*/
|
||||
decrementPendingCalls : function(category) {
|
||||
getCategory(category).pendingCalls--;
|
||||
getCategory(category).finishedCalls++;
|
||||
},
|
||||
|
||||
/**
|
||||
* <p>Increments the counter by 1. This method should be called if an Ajax request completes regardless if it
|
||||
* was successful or not.</p>
|
||||
*
|
||||
* @param {string} category
|
||||
* The category of the Ajax request.
|
||||
*/
|
||||
incrementPendingCalls : function(category) {
|
||||
getCategory(category).pendingCalls++;
|
||||
}
|
||||
}
|
||||
}();
|
||||
Reference in new issue
Block a user