Skip to content

Commit

Permalink
ApplicationTypeSchema api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-zinchenko committed Dec 27, 2024
1 parent 39a8067 commit cb5bc91
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ public class ControllerSelector {
ApplicationTypeSchemaController controller = new ApplicationTypeSchemaController(context);
String operation = pathMatcher.group(1);
return switch (operation) {
case "/schemas" -> controller::handleListSchemas;
case "/meta_schema" -> controller::handleGetMetaSchema;
case "/schema" -> controller::handleGetSchema;
case "schemas" -> controller::handleListSchemas;
case "meta_schema" -> controller::handleGetMetaSchema;
case "schema" -> controller::handleGetSchema;
default -> null;
};
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.epam.aidial.core.server;


import java.util.concurrent.atomic.AtomicReference;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.vertx.core.http.HttpMethod;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class ApplicationTypeSchemaApiTest extends ResourceBaseTest {

private final ObjectMapper objectMapper = new ObjectMapper();

@Test
void testApplicationTypeSchemaList_ok() {
Response response = send(HttpMethod.GET,"/v1/application_type_schemas/schemas",null, null);

Assertions.assertEquals(200, response.status());
AtomicReference<JsonNode> jsonNode = new AtomicReference<>();
Assertions.assertDoesNotThrow(() -> jsonNode.set(objectMapper.readTree(response.body())));
Assertions.assertTrue(jsonNode.get().isArray());
Assertions.assertFalse(jsonNode.get().isEmpty());
jsonNode.get().forEach(node -> {
Assertions.assertTrue(node.has("$id"));
Assertions.assertTrue(node.has("dial:applicationTypeEditorUrl"));
Assertions.assertTrue(node.has("dial:applicationTypeDisplayName"));
});
}

@Test
void testApplicationTypeSchemaMetaSchema_ok() {
Response response = send(HttpMethod.GET,"/v1/application_type_schemas/meta_schema",null, null);

Assertions.assertEquals(200, response.status());
AtomicReference<JsonNode> jsonNodeRef = new AtomicReference<>();
Assertions.assertDoesNotThrow(() -> jsonNodeRef.set(objectMapper.readTree(response.body())));
JsonNode node = jsonNodeRef.get();
Assertions.assertTrue(node.isObject());
Assertions.assertTrue(node.has("$id"));
Assertions.assertTrue(node.has("$schema"));
}

@Test
void testApplicationTypeSchemaSchema_ok() {
Response response = send(HttpMethod.GET,"/v1/application_type_schemas/schema",
"id=https://mydial.somewhere.com/custom_application_schemas/specific_application_type", null);

Assertions.assertEquals(200, response.status());
AtomicReference<JsonNode> jsonNodeRef = new AtomicReference<>();
Assertions.assertDoesNotThrow(() -> jsonNodeRef.set(objectMapper.readTree(response.body())));
JsonNode node = jsonNodeRef.get();
Assertions.assertTrue(node.isObject());
Assertions.assertTrue(node.has("$id"));
Assertions.assertTrue(node.has("$schema"));
}

}

0 comments on commit cb5bc91

Please sign in to comment.