Browse Source
AI rule node: add get by ID API tests
pull/13371/head
Dmytro Skarzhynets
1 year ago
No known key found for this signature in database
GPG Key ID: 2B51652F224037DF
1 changed files with
55 additions and
0 deletions
-
application/src/test/java/org/thingsboard/server/controller/AiModelControllerTest.java
|
|
|
@ -174,6 +174,61 @@ public class AiModelControllerTest extends AbstractControllerTest { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
/* --- Get by ID API tests --- */ |
|
|
|
|
|
|
|
@Test |
|
|
|
public void getAiModelById_whenUserIsSysAdmin_shouldReturnForbidden() throws Exception { |
|
|
|
// GIVEN
|
|
|
|
loginSysAdmin(); |
|
|
|
|
|
|
|
// WHEN
|
|
|
|
ResultActions result = doGet("/api/ai/model/" + Uuids.timeBased()); |
|
|
|
|
|
|
|
// THEN
|
|
|
|
result.andExpect(status().isForbidden()).andExpect(statusReason(equalTo(msgErrorPermission))); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void getAiModelById_whenUserIsCustomerUser_shouldReturnForbidden() throws Exception { |
|
|
|
// GIVEN
|
|
|
|
loginCustomerUser(); |
|
|
|
|
|
|
|
// WHEN
|
|
|
|
ResultActions result = doGet("/api/ai/model/" + Uuids.timeBased()); |
|
|
|
|
|
|
|
// THEN
|
|
|
|
result.andExpect(status().isForbidden()).andExpect(statusReason(equalTo(msgErrorPermission))); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void getAiModelById_whenGettingExistingModelAsTenantAdmin_shouldReturnModel() throws Exception { |
|
|
|
// GIVEN
|
|
|
|
loginTenantAdmin(); |
|
|
|
|
|
|
|
var saved = doPost("/api/ai/model", constructValidModel(), AiModel.class); |
|
|
|
|
|
|
|
// WHEN
|
|
|
|
AiModel actual = doGet("/api/ai/model/" + saved.getId(), AiModel.class); |
|
|
|
|
|
|
|
// THEN
|
|
|
|
assertThat(actual).isEqualTo(saved); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void getAiModelById_whenGettingNonexistentModelAsTenantAdmin_shouldReturnNotFound() throws Exception { |
|
|
|
// GIVEN
|
|
|
|
loginTenantAdmin(); |
|
|
|
|
|
|
|
var nonexistentModelId = new AiModelId(Uuids.timeBased()); |
|
|
|
|
|
|
|
// WHEN
|
|
|
|
ResultActions result = doGet("/api/ai/model/" + nonexistentModelId); |
|
|
|
|
|
|
|
// THEN
|
|
|
|
result.andExpect(status().isNotFound()) |
|
|
|
.andExpect(statusReason(is("AI model with id [" + nonexistentModelId + "] is not found"))); |
|
|
|
} |
|
|
|
|
|
|
|
/* --- Delete API tests --- */ |
|
|
|
|
|
|
|
@Test |
|
|
|
|