3 changed files with 57 additions and 49 deletions
@ -0,0 +1,48 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.script; |
|||
|
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.script.api.ScriptType; |
|||
import org.thingsboard.script.api.tbel.TbelInvokeService; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.controller.AbstractControllerTest; |
|||
|
|||
import java.util.Map; |
|||
import java.util.UUID; |
|||
import java.util.concurrent.ExecutionException; |
|||
|
|||
import static org.thingsboard.server.common.data.msg.TbMsgType.POST_TELEMETRY_REQUEST; |
|||
|
|||
public abstract class AbstractTbelInvokeTest extends AbstractControllerTest { |
|||
|
|||
@Autowired |
|||
protected TbelInvokeService invokeService; |
|||
|
|||
protected UUID evalScript(String script) throws ExecutionException, InterruptedException { |
|||
return invokeService.eval(TenantId.SYS_TENANT_ID, ScriptType.RULE_NODE_SCRIPT, script, "msg", "metadata", "msgType").get(); |
|||
} |
|||
|
|||
protected String invokeScriptResultString(UUID scriptId, String str) throws ExecutionException, InterruptedException { |
|||
var msg = JacksonUtil.fromString(str, Map.class); |
|||
return invokeScript(scriptId, str).toString(); |
|||
} |
|||
protected Object invokeScript(UUID scriptId, String str) throws ExecutionException, InterruptedException { |
|||
var msg = JacksonUtil.fromString(str, Map.class); |
|||
return invokeService.invokeScript(TenantId.SYS_TENANT_ID, null, scriptId, msg, "{}", POST_TELEMETRY_REQUEST.name()).get(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue