コード例 #1
0
 public void onReceive(android.content.Context context, android.content.Intent intent) {
   try {
     System.out.println("onReceive: " + rubyInstance);
     Script.put("$context", context);
     Script.put("$broadcast_receiver", this);
     Script.put("$intent", intent);
     if (rubyInstance != null) {
       Script.exec("$ruby_broadcast_receiver.on_receive($context, $intent)");
     } else {
       Script.execute("$broadcast_receiver.on_receive($context, $intent)");
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #2
0
 protected void loadScript() {
   Script.put("$broadcast_receiver", this);
   if (scriptName != null) {
     try {
       new Script(scriptName).execute();
       String rubyClassName = Script.toCamelCase(scriptName);
       System.out.println("Looking for Ruby class: " + rubyClassName);
       Object rubyClass = Script.get(rubyClassName);
       if (rubyClass != null) {
         System.out.println("Instanciating Ruby class: " + rubyClassName);
         Script.put("$java_broadcast_receiver", this);
         Script.exec(
             "$ruby_broadcast_receiver = " + rubyClassName + ".new($java_broadcast_receiver)");
         rubyInstance = Script.get("$ruby_broadcast_receiver");
       }
     } catch (IOException e) {
       throw new RuntimeException("IOException loading broadcast receiver script", e);
     }
   }
 }
コード例 #3
0
 @Test(
     threadPoolSize = 4,
     invocationCount = 10,
     timeOut = 1000,
     dataProvider = "Data-Provider-Function",
     dependsOnMethods = {"testEval"})
 public void parameterIntTest(ScriptEntry scriptEntry) throws Exception {
   Script script = scriptEntry.getScript(new RootContext());
   script.put("ketto", 2);
   assertThat(script.eval()).isEqualTo(3);
 }
コード例 #4
0
  @Test
  public void testResource() throws Exception {
    ScriptName scriptName = new ScriptName("resource", getLanguageName());
    ScriptEntry scriptEntry = getScriptRegistry().takeScript(scriptName);
    Assert.assertNotNull(scriptEntry);

    Script script = scriptEntry.getScript(new RootContext());
    // Set RequestLevel Scope
    script.put("ketto", 2);
    script.putSafe("callback", mock(Function.class));

    JsonValue createContent = new JsonValue(new LinkedHashMap<String, Object>());
    createContent.put("externalId", "701984");
    createContent.put("userName", "*****@*****.**");
    createContent.put(
        "assignedDashboard", Arrays.asList("Salesforce", "Google", "ConstantContact"));
    createContent.put("displayName", "Babs Jensen");
    createContent.put("nickName", "Babs");

    JsonValue updateContent = createContent.copy();
    updateContent.put("_id", UUID.randomUUID().toString());
    updateContent.put("profileUrl", "https://login.example.com/bjensen");

    final Context context =
        new ApiInfoContext(
            new SecurityContext(new RootContext(), "*****@*****.**", null), "", "");
    script.put("context", context);

    CreateRequest createRequest = Requests.newCreateRequest("/Users", "701984", createContent);
    script.put("createRequest", createRequest);
    ReadRequest readRequest = Requests.newReadRequest("/Users/701984");
    script.put("readRequest", readRequest);
    UpdateRequest updateRequest = Requests.newUpdateRequest("/Users/701984", updateContent);
    script.put("updateRequest", updateRequest);
    PatchRequest patchRequest =
        Requests.newPatchRequest("/Users/701984", PatchOperation.replace("userName", "ddoe"));
    script.put("patchRequest", patchRequest);
    QueryRequest queryRequest = Requests.newQueryRequest("/Users/");
    script.put("queryRequest", queryRequest);
    DeleteRequest deleteRequest = Requests.newDeleteRequest("/Users/701984");
    script.put("deleteRequest", deleteRequest);
    ActionRequest actionRequest = Requests.newActionRequest("/Users", "clear");
    script.put("actionRequest", actionRequest);
    script.eval();
  }
コード例 #5
0
  @Test
  public void testEval() throws Exception {
    ScriptName scriptName = new ScriptName("test1", getLanguageName());
    ScriptEntry scriptEntry = getScriptRegistry().takeScript(scriptName);
    Assert.assertNotNull(scriptEntry);
    scriptEntry.put("egy", 1);
    assertThat(scriptEntry.getScript(new RootContext()).eval()).isEqualTo(3);

    // Load Script from Directory
    scriptEntry = getScriptRegistry().takeScript(new ScriptName("sample", getLanguageName()));
    Assert.assertNotNull(scriptEntry);

    // Set ServiceLevel Scope
    scriptEntry.put("egy", 1);
    Script script = scriptEntry.getScript(new RootContext());

    // Set RequestLevel Scope
    script.put("ketto", 2);
    assertThat(script.eval()).isEqualTo(3);
  }