module.exports = Base.extend({ // equivlent to `finally` for non-ES5 environments ensure: function (fn) { var self = this; if (fn) { this.defer.promise.ensure(function() { fn.call(self, self.resourceToken); }); } return this; }, complete: function (fn, efn) { this.defer.promise.done(fn, efn); return this; }, error: function (fn) { this.defer.promise.otherwise(fn); return this; }, resolve: function (result) { this.defer.resolve({ task: this.task, result: result }); }, reject: function (err) { this.defer.reject(err); } });
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more * details. */ var Base = require('selfish').Base, Enum = require('enum'), taskEnum = new Enum(['DISCRETE', 'POOLED', 'BACKGROUND'], 'RTaskType'); /** * Defines the currently supported set of `RTask`. * * @module rtask-type * @for rbroker */ module.exports = Base.extend({ /** * Discrete task. */ DISCRETE: taskEnum.DISCRETE, /** * Pooled task. */ POOLED: taskEnum.POOLED, /** * Background task. */ BACKGROUND: taskEnum.BACKGROUND });
/*! * Copyright (C) 2010-2014 by Revolution Analytics Inc. * * This program is licensed to you under the terms of Version 2.0 of the * Apache License. This program is distributed WITHOUT * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more * details. */ var Base = require('selfish').Base, RTaskType = require('../rtask-type'), RTask = require('./rtask'); module.exports = Base.extend(RTask, { initialize: function(props) { RTask.initialize.call(this, props, RTaskType.DISCRETE); }, toString: function() { return 'DiscreteTask: ' + RTask.toString.call(this); } });
var RTaskQueue = Base.extend({ initialize: function (capacity) { this.capacity = capacity; this.q = []; }, /** * Inserts the specified element at the tail of this queue if it is possible * to do so immediately without exceeding the queue's capacity, returning * ```true``` upon success and ```false``` if this queue is full. */ offer: function (rtask) { var accepting = this.size() < this.capacity; if (accepting) { this.q.push(rtask); } return accepting; // True if added False otherwise }, /** * Retrieves and removes the head of this queue. */ take: function () { return this.q.shift(); }, /** * Retrieves, but does not remove, the head of this queue, or returns ` * ``null`` if this queue is empty. */ peek: function () { return this.q[0]; }, /** * Returns the number of elements in this queue. */ size: function () { return this.q.length; }, /** * Returns ```true``` if this collection contains no elements. * This implementation returns size() === 0. */ isEmpty: function () { return this.size() === 0; }, clear: function () { this.q.length = 0; }, iter: function (fn) { this.q.forEach(fn); } });
var Types = base.extend({ /** * Must be implemented by subclasses. * Returns the type list. * @return {array} the type list. * @throws UnimplementedOperationException if the method has not been * implemented by the subclass. */ getTypes: function() { throw new UnimplementedOperationException( 'This method must be implemented by a subclass to be called.'); }, /** * Must be implemented by subclasses. * Returns the validations for the passed type. * @param type {string} the type. * @return {array} the validation list. * @throws UnimplementedOperationException if the method has not been * implemented by the subclass. * @throws NoElementFoundException if no type exists for the passed type. */ getValidationsForType: function(type) { throw new UnimplementedOperationException( 'This method must be implemented by a subclass to be called.'); }, /** * This method converts the internal type map into another array. * Each element is an Object which has a name, and a value. * By default, the name and the value keys have the same value: * [ { name: '1', value: '1' }, { name: '2', value: '2' }, ... ] * @return {array} the new array. */ toValueNameObjectArray: function() { var array = []; for (var key in this.getTypes()) { if(this.getTypes().hasOwnProperty(key)) { var object = { value: this.getTypes()[key], name: this.getTypes()[key] }; array.push(object); } } return array; }, /** * Checks whether the type is contained in the supported types. * @param {string} type the type to check. * @return {boolean} whether the type is contained in the supported types. */ contains: function(type) { return this.getTypes().indexOf(type) !== -1; }, /** * Checks whether the type possesses the also passed validation. * @param type {string} the type. * @param validation {string} the validation to check. * @return {boolean} whether the type is validated by the validation. * @throws NoElementFoundException if no type exists for the passed type. */ isValidationSupportedForType: function(type, validation) { return this.getValidationsForType(type).indexOf(validation) !== -1; } });
module.exports = Base.extend({ /** * Represents a handle to an `RTask` live on an `RBroker`. * * @class * @constructor * @param {RTask} The task worker. */ initialize: function initialize(worker) { this.worker = worker; this.cancelled = false; }, /** * Terminates `this` running task. * * @method cancel * @param {Boolean} Permission to interrupt task if it is running. * @return {RTaskToken} for chaining. * @api public */ cancel: function(interrupt) { // RTask completed (resolved|rejected), can not be cancelled. this.cancelled = this.worker.terminate(interrupt); return this.cancelled; }, /** * Returns the `RTask` associated with this `RTaskToken`. * * @method getTask * @return {RTaskToken} for chaining. * @api public */ getTask: function() { return this.worker.task; }, /** * Returns `true` if this task completed. Completion may be due to normal * termination, an exception, or cancellation -- in all of these cases, * this method will return `true`. * * @deprecated * @method isDone * @return {Boolean} If `this` task is completed. * @api public */ isDone: function() { return !this.isPending(); }, /** * Returns `false` if this task completed. Completion may be due to normal * termination, an exception, or cancellation -- in all of these cases, * this method will return `true`. * * @method isPending * @return {Boolean} `true` if this task has not yet been completed. * @api public */ isPending: function() { return this.worker.isPending(); }, /** * Returns `true` if this task was cancelled before it completed normally. * * @method isCancelled * @return {Boolean} `true` if this task was cancelled before it completed. * @api public */ isCancelled: function() { return this.cancelled; }, /** * The `.promise()` method returns a dynamically generated Promise that is * resolved once this task has completed. * * @method promise * @return {Promise} A promise wrapping the resolution of either "resolve" * or "reject" callback. * @api public */ promise: function() { return this.worker.defer.promise; } });
/*! * Copyright (C) 2010-2014 by Revolution Analytics Inc. * * This program is licensed to you under the terms of Version 2.0 of the * Apache License. This program is distributed WITHOUT * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the * Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more * details. */ var Base = require('selfish').Base, RTaskType = require('../rtask-type'), RTask = require('./rtask'); module.exports = Base.extend(RTask, { initialize: function(props) { RTask.initialize.call(this, props, RTaskType.POOLED); }, toString: function() { return 'PooledTask: ' + RTask.toString.call(this); } });
* Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0) for more * details. */ var Base = require('selfish').Base; module.exports = Base.extend({ initialize: function(config) { this.props = config; }, toJSON: function() { var clone = {}; for(var keys = Object.keys(this.props), l = keys.length; l; --l) { clone[ keys[l-1] ] = this.props[ keys[l-1] ]; } return clone; }, toString: function() { var out = 'PooledTask: '; for(var o in this.props) { out += ' [ ' + o + ' = "' + this.props[o] + '" ]'; } return out; } });
var BaseComponent = selfish.extend({ initialize: function(test, angularSupportEnabled) { this.angularSupportEnabled = _.isBoolean(angularSupportEnabled) ? angularSupportEnabled : false; this.test = test; this.baseSelector = this.baseSelector || ''; this.selectors = this.selectors || {}; }, waitForAngular: function() { //this configuration allow this base system to be used with non-angular applications if(this.angularSupportEnabled === true) { this.test.waitFor(scripts.angular); } }, typeElement: function(selector, keys, waitForAngular) { //more often then not, not waiting for angular can cause test to randomly fail but for a small set of test, this is sometimes needed waitForAngular = _.isBoolean(waitForAngular) ? waitForAngular : true; this.test.type(selector, keys); if(waitForAngular === true) { this.waitForAngular(); } }, sendKeysToPage: function(keys) { this.test.sendKeys('body', keys); this.waitForAngular(); }, clickBody: function() { this.test.click('body'); this.waitForAngular(); }, getSelector: function(name, withBase) { withBase = _.isBoolean(withBase) ? withBase : true; var selector = ''; if(name && this.selectors[name]) { selector = this.selectors[name]; } if(withBase && this.baseSelector) { selector = this.baseSelector + ' ' + selector; } return selector; }, done: function() { this.test.done(); } });