@Test public void shouldReturnEncodedState() throws Exception { // GIVEN JavaScriptObject givenStateObject = mock(JavaScriptObject.class); JSONArray encodedState = mock(JSONArray.class); when(externalApiProvider.getExternalApi().getStateFromExternal()).thenReturn(givenStateObject); when(stateEncoder.encodeState(givenStateObject)).thenReturn(encodedState); // WHEN JSONArray result = testObj.getState(); // THEN assertThat(result).isEqualTo(encodedState); verify(externalStateSaver).setExternalState(givenStateObject); }
public static JavaScriptObject createSocketObject(Object module) { JavaScriptObject jso = JavaScriptObject.createObject(); jso = addObjectFunctions(jso, module.getClass().getName()); if (module instanceof Lockable) { jso = addLockableFunctions(jso, module); } if (module instanceof Resetable) { jso = addResetableFunctions(jso, module); } if (module instanceof Activity) { jso = addActivityFunctions(jso, module); } if (module instanceof IUniqueModule) { jso = addUniqueFunctions(jso, module); } return jso; }
public static void peopleLookup(String query, final JavaScriptObject callback, String options) { final Lookup lookup = new Lookup(); if (query != null && !query.trim().isEmpty()) lookup.setQuery(query); lookup.addValueChangeHandler(new ValueChangeHandler<PersonInterface>() { @Override public void onValueChange(ValueChangeEvent<PersonInterface> event) { if (event.getValue() != null) lookup.fireCallback(callback, event.getValue().getId(), event.getValue().getFirstName(), event.getValue().getMiddleName(), event.getValue().getLastName(), event.getValue().getEmail(), event.getValue().getPhone(), event.getValue().getAcademicTitle(), event.getValue().getName()); } }); lookup.setOptions(options); lookup.center(); }
public static FlowActivityEvent fromJsObject(JavaScriptObject jsObject) { String currTypeString = getTypeJs(jsObject); final String groupIdentifierString = getGroupIdentifierJs(jsObject); // NOPMD if (currTypeString != null) { currTypeString = currTypeString.trim().toUpperCase(); for (FlowActivityEventType currType : FlowActivityEventType.values()) { if (currType.toString().equals(currTypeString)) { return new FlowActivityEvent(currType, new GroupIdentifier() { // NOPMD @Override public String getIdentifier() { return groupIdentifierString; } }); } } } return null; }
public void testShouldGetStateObject() { // given JavaScriptObject state = JavaScriptObject.createObject(); JSONArray stateArray = new JSONArray(); stateArray.set(0, new JSONObject(state)); JSONObject stateObject = new JSONObject(); stateObject.put("STATE", stateArray); JSONArray jsonArray = new JSONArray(); jsonArray.set(0, stateObject); // when JavaScriptObject result = testObj.decodeState(jsonArray); // then assertEquals(result, state); }
private native final JavaScriptObject getDesktopOptions() /*-{ var options = { link: false, indent: false, outdent: false, unlink: false, remove: false, source: false, rule: false }; return options; }-*/;
/** * Returns the plugin options, if exist. * @param pluginId plugin id. * @return java script object used to configure the plugin or <code>null</code> if not exist. * @throws InvalidPluginIdException occurs if the plugin id is invalid. */ public JavaScriptObject getOptions(String pluginId) throws InvalidPluginIdException{ // checks the plugin id PluginIdChecker.check(pluginId); // returns the configuration creating a key by plugin id. return getValue(new StandardKey(pluginId)); }
private native int callImportInitialItemIndex(JavaScriptObject playerJsObject)/*-{ var itemIndex = -1; if (typeof playerJsObject.importInitialItemIndex == 'function') { var importedIndex = playerJsObject.importInitialItemIndex(); if (!isNaN(importedIndex)) { itemIndex = parseInt(importedIndex); } } return itemIndex; }-*/;
private static native JavaScriptObject addObjectFunctions(JavaScriptObject jso, String className)/*-{ var instanceClassName = className; jso.getClassName = function () { return instanceClassName; } return jso; }-*/;
@Override public void processSingleAction(FeedbackAction action, FeedbackMark mark) { ShowTextAction textAction = (ShowTextAction) action; feedbackCounter.add(textAction); Element element = textAction.getContent().getValue(); Widget widget = inlineBodyGenerator.generateInlineBody(element); feedbackPresenter.setFeedbackContent(widget, mark); JavaScriptObject mathJaxCallback = createCallback(textAction); mathJaxNative.renderMath(mathJaxCallback); }
@Override public JavaScriptObject toJsObject() { String giString = ""; if (getGroupIdentifier() != null) giString = getGroupIdentifier().getIdentifier(); return createRequestJsObject(getName(), giString); }
private native JavaScriptObject createPageInterferenceSocketJs(JavaScriptObject socketJs)/*-{ var instance = this; var socket = []; var ais = socketJs; socket.getPageInterferenceSocket = function () { return ais; } return socket; }-*/;
private void setOptions() { JavaScriptObject flowOptionsJs = callImportFlowOptionsJs(playerJsObject); if (flowOptionsJs != null) { FlowOptions flowOptions = FlowOptions.fromJsObject(flowOptionsJs); deliveryEngineSocket.setFlowOptions(flowOptions); } JavaScriptObject displayOptionsJs = callImportDisplayOptionsJs(playerJsObject); if (displayOptionsJs != null) { DisplayOptions displayOptions = DisplayOptions.fromJsObject(displayOptionsJs); deliveryEngineSocket.setDisplayOptions(displayOptions); } }
/** * Sets the plugin options. If passed otpions is null, the configuration of plugin will be removed. * @param pluginId plugin id. * @param options java script object used to configure the plugin. Pass <code>null</code> to remove the configuration if exist. * @throws InvalidPluginIdException occurs if the plugin id is invalid. */ public void setOptions(String pluginId, JavaScriptObject options) throws InvalidPluginIdException { // checks the plugin id PluginIdChecker.check(pluginId); // creates a key using plugin ID Key key = new StandardKey(pluginId); // if null, removes the configuration if (options == null){ // removes configuration if exists removeIfExists(key); } else { // stores configuration setValue(key, options); } }
public void testDeliveryEventsPageSwitch() { types = typesPageSwitch; PlayerGinjector injector = PlayerGinjectorFactory.getNewPlayerGinjectorForGWTTestCase(); de = injector.getDeliveryEngine(); de.init(JavaScriptObject.createObject()); Extension ext = new MockDeliveryEventsListenerExtension(); de.setFlowOptions(new FlowOptions(true, false, PageItemsDisplayMode.ONE, ActivityMode.NORMAL)); de.loadExtension(ext); de.load(getAssessmentXMLData(), getItemXMLDatas()); }
public void testShouldSerializeEventWithTypeAndPageIndex() { // given PageChangedEvent testObj = new PageChangedEvent(EXPECTED_PAGE_INDEX); // when JavaScriptObject actual = testObj.getJSONObject(); JSONObject actualJSON = new JSONObject(actual); // then double actualPage = actualJSON.get("payload").isObject().get("new_page").isNumber().doubleValue(); assertEquals(actualPage, EXPECTED_PAGE_INDEX, DELTA); String actualEventType = actualJSON.get("type").isString().stringValue(); assertEquals(actualEventType, "page_changed"); }
private CssHelper createCssHelperMock() { CssHelper cssHelper = spy(new CssHelper()); Style style = mock(Style.class); doReturn("none").when(style).getProperty(Matchers.anyString()); doReturn(style).when(cssHelper).getComputedStyle(Matchers.any(JavaScriptObject.class)); return cssHelper; }
private native void onComplete(JavaScriptObject soundInstance)/*-{ if (typeof soundInstance.onComplete == 'function') { soundInstance.onComplete(soundInstance); } }-*/;
private JavaScriptObject getFlowOptionsJs() { return supplier.getFlowOptions().toJsObject(); }
private native String getStateJs(JavaScriptObject extension)/*-{ if (typeof extension.getStateString == 'function') { return extension.getStateString(); } return null; }-*/;
@Override public boolean onBeforeEvent(AbstractChart<?, ?> chart, ChartNativeEvent event, JavaScriptObject options){ return true; }
public void resumeAnimation(JavaScriptObject context) { callMethod(context, METHOD_NAME_RESUME_ANIMATION); }
public void onWindowResized(JavaScriptObject context) { callMethod(context, METHOD_NAME_WINDOW_RESIZED); }
private void callMethod(JavaScriptObject context, String methodName) { methodInvocator.callMethod(context, methodName); }
public static native JavaScriptObject fillArray(JavaScriptObject array, String index, boolean item)/*-{ array[index] = item; return array; }-*/;
private final native String getBonusIdNative(JavaScriptObject extensionJsObject)/*-{ return extensionJsObject.getBonusId(); }-*/;
@Override public JavaScriptObject getOptions() { return getDesktopOptions(); }
private native void setSessionDataSocketJs(JavaScriptObject extension, JavaScriptObject socket)/*-{ if (typeof extension.setSessionDataSocket == 'function') { extension.setSessionDataSocket(socket); } }-*/;
@Override public void onBeforeInit(AbstractChart<?, ?> chart, JavaScriptObject options){ }
@Override public JavaScriptObject getJsSocket() { return ModuleJsSocketFactory.createSocketObject(this); }
public void renderMath(JavaScriptObject callback) { renderMathNative(callback); }