Created
January 20, 2012 02:03
-
-
Save natecavanaugh/1644528 to your computer and use it in GitHub Desktop.
Verify Service API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Verify service API | |
AUI().use( | |
'async-queue', | |
function(A) { | |
var q = new A.AsyncQueue(); | |
window.q = q; | |
q.after( | |
'complete', | |
function(event) { | |
console.log('expectedCount: %d, successCount: %d, exceptionCount: %d, reached expectedCount: %b',expectedCount, successCount, exceptionCount, expectedCount === (successCount + exceptionCount)); | |
} | |
); | |
var service = 'user/get-user-id-by-email-address'; | |
window.successCount = 0; | |
window.exceptionCount = 0; | |
window.expectedCount = 0; | |
window.exceptions = []; | |
var wait = function() { | |
expectedCount += 1; | |
q.pause(); | |
}; | |
var exceptionCallback = function(msg, obj) { | |
console.log('exception', msg, obj); | |
exceptions[exceptionCount] = msg; | |
exceptionCount += 1; | |
q.run(); | |
}; | |
var successCallback = function(obj) { | |
console.log('success', obj); | |
successCount += 1; | |
q.run(); | |
}; | |
var data = { | |
companyId: 10160, | |
emailAddress: '[email protected]' | |
}; | |
var form = A.Node.create(A.Lang.sub('<form id="fmTest" name="fmTest"><input type="text" name="companyId" value="{companyId}" /><input type="text" name="emailAddress" value="{emailAddress}" /></form>', data)).appendTo('body'); | |
var Service = Liferay.Service; | |
A.each( | |
[null, 'get', 'del', 'post', 'put', 'update'], | |
function(item, index, collection) { | |
var serviceMethod = item ? Service[item] : Service; | |
q.add(function() { serviceMethod(service); }); | |
q.add(function() { wait(); serviceMethod(service, successCallback); }); | |
q.add(function() { wait(); serviceMethod(service, successCallback, exceptionCallback); }); | |
q.add(function() { serviceMethod(service, data); }); | |
q.add(function() { wait(); serviceMethod(service, data, successCallback); }); | |
q.add(function() { wait(); serviceMethod(service, data, successCallback, exceptionCallback); }); | |
q.add(function() { wait(); serviceMethod(service, form, successCallback); }); | |
q.add(function() { wait(); serviceMethod(service, '#fmTest', successCallback, exceptionCallback); }); | |
A.each( | |
[data, form, '#fmTest', form._node], | |
function(item1, index1, collection1) { | |
var serviceConfig = {}; | |
serviceConfig[service] = item1; | |
q.add(function() { serviceMethod(serviceConfig); }); | |
q.add(function() { wait(); serviceMethod(serviceConfig, successCallback); }); | |
q.add(function() { wait(); serviceMethod(serviceConfig, successCallback, exceptionCallback); }); | |
} | |
); | |
} | |
); | |
q.run(); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment