Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to best Test (Unit Test) WL Adapters independent from WL App? + Jasmine Tests: Cannot use 'in' operator to search for 'SUPPORT_COOKIES' in null
    primarykey
    data
    text
    <p>Related to this question: <a href="https://stackoverflow.com/questions/15214750/uncaught-typeerror-cannot-use-in-operator-to-search-for-support-cookies-in">Uncaught TypeError: Cannot use &#39;in&#39; operator to search for &#39;SUPPORT_COOKIES&#39; in null</a></p> <p>But different due to Jasmine Test-Tool and the general question about Best-Practices for JS-Java Adapter-Testing.</p> <hr> <p>We are working on setting up a development environment for a group of developers including continuous integration, build and automated testing.</p> <p>For this purpose, we need to have a way to call the WL Adapters on the WL servers from stand-alone test cases/clients (test code) that runs independent from the actual Worklight App or any Worklight client. These tests will have to run at deploy and continuous build and will test the adapters.</p> <p>We came up with this solution, because there is no way to test the Adapters locally, before they are deployed. Also, we can not really include test code into our adapters and deploy the code together with the Adapter. This would not be a nice solution and we would have test code on the server with the Adapter.</p> <p>We will probably use <strong>Jasmine</strong> and <strong>JUnit</strong> as our test tools and I tried to setup a stand-alone Jasmine Worklight Client/Test by including all Worklight JS libraries and variables (that the worklight compiler adds to the final compiled and deployed App .html) to my Jasmine test.</p> <p>It runs for some part and it seems to initialize ok:</p> <pre><code>wlclient init started worklight.js:1112 before: app init onSuccess worklight.js:1112 after: app init onSuccess worklight.js:1112 wlclient init success </code></pre> <p>but when I want to execute WL.Client.invokeProcedure(invocationData, I get the error:</p> <p><strong>TypeError: Cannot use 'in' operator to search for 'SUPPORT_COOKIES' in null</strong></p> <p>So there seems to be some configuration or initialization missing in my stand-alone Worklight Client/Test. Can anyone of the experts tell me what that could be?</p> <pre><code>&lt;head&gt; &lt;title&gt;Jasmine Spec Runner&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css"&gt; &lt;script&gt; // Define WL namespace. var WL = WL ? WL : {}; /** * WLClient configuration variables. * Values are injected by the deployer that packs the gadget. */ WL.StaticAppProps = { "APP_DISPLAY_NAME": "app", "APP_SERVICES_URL": "\/tests\/", "APP_VERSION": "1.0", "ENVIRONMENT": "preview", "HEIGHT": 460, "LOGIN_DISPLAY_TYPE": "popup", "LOGIN_POPUP_HEIGHT": 610, "LOGIN_POPUP_WIDTH": 920, "PREVIEW_ENVIRONMENT": "common", "WIDTH": 320, "WORKLIGHT_ROOT_URL": "\/tests\/" }; &lt;script src="lib/common/js/wljq.js"&gt;&lt;/script&gt; &lt;script src="lib/common/js/base.js"&gt;&lt;/script&gt; &lt;script src="lib/common/js/containerCommunicationAPI.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/messages.js"&gt;&lt;/script&gt; &lt;script src="lib/common/js/wlcommon.js"&gt;&lt;/script&gt; &lt;script src="lib/common/js/busy.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/diagnosticDialog.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/deviceAuthentication.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/window.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/worklight.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/gadgetCommunicationAPI.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/wlclient.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/wlfragments.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/encryptedcache.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/jsonstore/jsonstore.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/challengeHandlers/antiXSRFChallengeHandler.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/challengeHandlers/authenticityChallengeHandler.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/challengeHandlers/deviceAuthAutoProvisioningChallengeHandler.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/challengeHandlers/deviceAuthNoProvisioningChallengeHandler.js"&gt;&lt;/script&gt; &lt;script src="lib/wlclient/js/challengeHandlers/remoteDisableChallengeHandler.js"&gt;&lt;/script&gt; &lt;script src="../apps/app/common/js/jquery-1.10.1.min.js"&gt;&lt;/script&gt; &lt;!-- script&gt;window.$ = window.jQuery = WLJQ;&lt;/script--&gt; &lt;script src="../apps/app/common/jqueryMobile/jquery.mobile-1.3.1.js"&gt;&lt;/script&gt; &lt;script src="../apps/app/common/js/initOptions.js"&gt;&lt;/script&gt; &lt;script src="../apps/app/common/js/messages.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"&gt;&lt;/script&gt; &lt;!-- include source files here... --&gt; &lt;!--&lt;script type="text/javascript" src="../apps/app/common/js/knockout-2.2.1.js"&gt;&lt;/script&gt;--&gt; &lt;!--&lt;script type="text/javascript" src="../apps/app/common/js/knockout.mapping-latest.js"&gt;&lt;/script&gt;--&gt; &lt;!--&lt;script type="text/javascript" src="../apps/app/common/js/globalize.js"&gt;&lt;/script&gt;--&gt; &lt;!--&lt;script type="text/javascript" src="../apps/app/common/js/app.js"&gt;&lt;/script&gt; --&gt; &lt;!--&lt;script type="text/javascript" src="../apps/app/common/js/common.js"&gt;&lt;/script&gt;--&gt; &lt;!--&lt;script type="text/javascript" src="../apps/app/common/js/date.js"&gt;&lt;/script&gt;--&gt; &lt;!--&lt;script type="text/javascript" src="../apps/app/common/js/localize.js"&gt;&lt;/script&gt;--&gt; &lt;/script&gt;--&gt; &lt;!-- include spec files here... --&gt; &lt;!--script type="text/javascript" src="spec/SpecHelper.js"&gt;&lt;/script--&gt; &lt;script type="text/javascript" src="spec/TestSpec.js"&gt;&lt;/script&gt; </code></pre> <hr> <p><strong><em>July 15 2013:</em></strong></p> <p>Got Jasmine automatically running in WL Client this way:</p> <pre><code>var wlInitOptions = { connectOnStartup : false, }; if (window.addEventListener) { window.addEventListener('load', function() { WL.Client.init(wlInitOptions); execJasmine(); }, false); } else if (window.attachEvent) { window.attachEvent('onload', function() { WL.Client.init(wlInitOptions); execJasmine(); }); } function wlCommonInit(){ } var jasmineEnv = jasmine.getEnv(); jasmineEnv.updateInterval = 1000; var htmlReporter = new jasmine.HtmlReporter(); jasmineEnv.addReporter(htmlReporter); jasmineEnv.specFilter = function(spec) { return htmlReporter.specFilter(spec); }; function execJasmine() { WL.Logger.debug("ExecJasmine"); jasmineEnv.execute(); } </code></pre> <p>But now I am getting <strong>Access Control Problems</strong> because my WL-Jasmine-Test-Client is running on an <strong>Apache on port 80</strong> and the Adapters on the <strong>WL Server on port 8080</strong>.</p> <pre><code>running test worklight.js:1112 Application did not define an i18n messages object, skipping translation. worklight.js:1112 wlclient init started worklight.js:1112 before: app init onSuccess worklight.js:1112 after: app init onSuccess worklight.js:1112 wlclient init success worklight.js:1112 ExecJasmine worklight.js:1112 Request [http://XXX:8080/apps/services/api/app/desktopbrowser/query] worklight.js:1112 running test 2 worklight.js:1112 OPTIONS http://XXX:8080/apps/services/api/app/desktopbrowser/query 401 (Unauthorized) base.js:883 OPTIONS http://XXX:8080/apps/services/api/app/desktopbrowser/query Origin http://XXX is not allowed by Access-Control-Allow-Origin. base.js:883 XMLHttpRequest cannot load http://XXX:8080/apps/services/api/app/desktopbrowser/query. Origin http://XXX is not allowed by Access-Control-Allow-Origin. SpecRunnerAdapter.html:1 Refused to get unsafe header "X-JSON" base.js:994 [http://XXX:8080/apps/services/api/app/desktopbrowser/query] Host is not responsive. worklight.js:1112 {"invocationContext":null,"errorCode":"UNRESPONSIVE_HOST","errorMsg":"The service is currently not available."} worklight.js:1112 Refused to get unsafe header "X-JSON" </code></pre> <p>using this WL-Test-Client app configuration:</p> <pre><code> WL.StaticAppProps = { "APP_DISPLAY_NAME": "app", "APP_SERVICES_URL": "http:\/\/XXX:8080\/apps\/services\/", "APP_VERSION": "1.0", "ENVIRONMENT": "desktopbrowser", "HEIGHT": 460, "LOGIN_DISPLAY_TYPE": "popup", "LOGIN_POPUP_HEIGHT": 610, "LOGIN_POPUP_WIDTH": 920, "WIDTH": 320, "WORKLIGHT_ROOT_URL": "http:\/\/XXX:8080\/apps\/services\/api\/app\/desktopbrowser\/" }; </code></pre> <p><strong>I guess we will stop here and simply use the INVOKE service on the WL-Server to call <em>wl_unprotected Adapter Procedures</em> for our JUnit test in a test environment.</strong> </p> <p><strong>Then figure out how to secure the procedures for production at build/deploy and at the same time remove the unit test executions - since they won't work with secured Adapters anymore.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload