|
|
|
@ -32,8 +32,11 @@ import org.thingsboard.server.gen.edge.v1.UplinkResponseMsg; |
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
import java.util.UUID; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
import static org.awaitility.Awaitility.await; |
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
|
|
|
import static org.thingsboard.server.gen.edge.v1.UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE; |
|
|
|
|
|
|
|
@DaoSqlTest |
|
|
|
public class AiModelEdgeTest extends AbstractEdgeTest { |
|
|
|
@ -42,7 +45,7 @@ public class AiModelEdgeTest extends AbstractEdgeTest { |
|
|
|
private static final String UPDATED_AI_MODEL_NAME = "Updated Edge Test AiModel"; |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testAiModel_create_update_delete() throws Exception { |
|
|
|
public void testAiModel_create_update_delete_fromCloud() throws Exception { |
|
|
|
// create AiModel
|
|
|
|
AiModel aiModel = createSimpleAiModel(DEFAULT_AI_MODEL_NAME); |
|
|
|
|
|
|
|
@ -91,26 +94,29 @@ public class AiModelEdgeTest extends AbstractEdgeTest { |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testSendAiModelToCloud() throws Exception { |
|
|
|
AiModel aiModel = createSimpleAiModel(DEFAULT_AI_MODEL_NAME); |
|
|
|
UUID uuid = Uuids.timeBased(); |
|
|
|
UplinkMsg uplinkMsg = getUplinkMsg(uuid, aiModel, UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE); |
|
|
|
|
|
|
|
checkAiModelOnCloud(uplinkMsg, uuid, aiModel.getName()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testUpdateAiModelNameOnCloud() throws Exception { |
|
|
|
public void testAiModel_create_update_delete_toCloud() throws Exception { |
|
|
|
// create
|
|
|
|
AiModel aiModel = createSimpleAiModel(DEFAULT_AI_MODEL_NAME); |
|
|
|
UUID uuid = Uuids.timeBased(); |
|
|
|
UplinkMsg uplinkMsg = getUplinkMsg(uuid, aiModel, UpdateMsgType.ENTITY_CREATED_RPC_MESSAGE); |
|
|
|
|
|
|
|
checkAiModelOnCloud(uplinkMsg, uuid, aiModel.getName()); |
|
|
|
|
|
|
|
// update
|
|
|
|
aiModel.setName(UPDATED_AI_MODEL_NAME); |
|
|
|
UplinkMsg updatedUplinkMsg = getUplinkMsg(uuid, aiModel, UpdateMsgType.ENTITY_UPDATED_RPC_MESSAGE); |
|
|
|
|
|
|
|
checkAiModelOnCloud(updatedUplinkMsg, uuid, aiModel.getName()); |
|
|
|
|
|
|
|
// delete
|
|
|
|
UplinkMsg deleteUplinkMsg = getDeleteUplinkMsg(uuid); |
|
|
|
edgeImitator.expectResponsesAmount(1); |
|
|
|
edgeImitator.sendUplinkMsg(deleteUplinkMsg); |
|
|
|
Assert.assertTrue(edgeImitator.waitForResponses()); |
|
|
|
|
|
|
|
await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> |
|
|
|
doGet("/api/ai/model/" + uuid, AiModel.class, status().isNotFound()) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -164,6 +170,20 @@ public class AiModelEdgeTest extends AbstractEdgeTest { |
|
|
|
return aiModel; |
|
|
|
} |
|
|
|
|
|
|
|
private UplinkMsg getDeleteUplinkMsg(UUID uuid) throws InvalidProtocolBufferException { |
|
|
|
UplinkMsg.Builder upLinkMsgBuilder = UplinkMsg.newBuilder(); |
|
|
|
AiModelUpdateMsg.Builder aiModelDeleteMsgBuilder = AiModelUpdateMsg.newBuilder(); |
|
|
|
aiModelDeleteMsgBuilder.setMsgType(ENTITY_DELETED_RPC_MESSAGE); |
|
|
|
aiModelDeleteMsgBuilder.setIdMSB(uuid.getMostSignificantBits()); |
|
|
|
aiModelDeleteMsgBuilder.setIdLSB(uuid.getLeastSignificantBits()); |
|
|
|
testAutoGeneratedCodeByProtobuf(aiModelDeleteMsgBuilder); |
|
|
|
|
|
|
|
upLinkMsgBuilder.addAiModelUpdateMsg(aiModelDeleteMsgBuilder.build()); |
|
|
|
testAutoGeneratedCodeByProtobuf(upLinkMsgBuilder); |
|
|
|
|
|
|
|
return upLinkMsgBuilder.build(); |
|
|
|
} |
|
|
|
|
|
|
|
private UplinkMsg getUplinkMsg(UUID uuid, AiModel aiModel, UpdateMsgType updateMsgType) throws InvalidProtocolBufferException { |
|
|
|
UplinkMsg.Builder uplinkMsgBuilder = UplinkMsg.newBuilder(); |
|
|
|
AiModelUpdateMsg.Builder aiModelUpdateMsgBuilder = AiModelUpdateMsg.newBuilder(); |
|
|
|
|