diff --git a/server/src/main/java/com/epam/aidial/core/server/util/ApplicationTypeSchemaUtils.java b/server/src/main/java/com/epam/aidial/core/server/util/ApplicationTypeSchemaUtils.java index 2fbef926..9bf2cb44 100644 --- a/server/src/main/java/com/epam/aidial/core/server/util/ApplicationTypeSchemaUtils.java +++ b/server/src/main/java/com/epam/aidial/core/server/util/ApplicationTypeSchemaUtils.java @@ -103,7 +103,7 @@ public static String getCustomApplicationEndpoint(Config config, Application app throw new ApplicationTypeSchemaProcessingException("Custom application schema does not contain completion endpoint"); } return endpointNode.asText(); - } catch (JsonProcessingException e) { + } catch (JsonProcessingException | IllegalArgumentException e) { throw new ApplicationTypeSchemaProcessingException("Failed to get custom application endpoint", e); } } diff --git a/server/src/test/java/com/epam/aidial/core/server/util/ApplicationTypeSchemaUtilsTest.java b/server/src/test/java/com/epam/aidial/core/server/util/ApplicationTypeSchemaUtilsTest.java index a98ccfe5..7b4c8585 100644 --- a/server/src/test/java/com/epam/aidial/core/server/util/ApplicationTypeSchemaUtilsTest.java +++ b/server/src/test/java/com/epam/aidial/core/server/util/ApplicationTypeSchemaUtilsTest.java @@ -93,7 +93,7 @@ public void getCustomApplicationSchemaOrThrow_returnsSchema_whenSchemaIdExists() } @Test - public void getCustomApplicationSchemaOrThrow_throwsException_whenSchemaNotFound() { + public void getCustomApplicationSchemaOrThrow_throws_whenSchemaNotFound() { URI schemaId = URI.create("schemaId"); when(application.getCustomAppSchemaId()).thenReturn(schemaId); when(config.getCustomApplicationSchema(schemaId)).thenReturn(null); @@ -189,4 +189,47 @@ public void filterCustomClientPropertiesWhenNoWriteAccess_returnsOriginalApplica Assertions.assertEquals(customProperties, result.getCustomProperties()); } + @Test + public void modifyEndpointForCustomApplication_setsCustomEndpoint_whenSchemaExists() { + when(application.getCustomAppSchemaId()).thenReturn(URI.create("schemaId")); + when(config.getCustomApplicationSchema(any())).thenReturn(schema); + + Application result = ApplicationTypeSchemaUtils.modifyEndpointForCustomApplication(config, application); + + Assertions.assertNotSame(application, result); + Assertions.assertEquals("http://specific_application_service/opeani/v1/completion", result.getEndpoint()); + } + + @Test + public void modifyEndpointForCustomApplication_throws_whenSchemaIsNull() { + when(application.getCustomAppSchemaId()).thenReturn(null); + + Assertions.assertThrows(ApplicationTypeSchemaProcessingException.class, + () -> ApplicationTypeSchemaUtils.modifyEndpointForCustomApplication(config, application)); + } + + @Test + public void modifyEndpointForCustomApplication_throws_whenEndpointNotFound() { + String schemaWithoutEndpoint = "{" + + "\"$schema\": \"https://dial.epam.com/application_type_schemas/schema#\"," + + "\"$id\": \"https://mydial.epam.com/custom_application_schemas/specific_application_type\"," + + "\"properties\": {" + + " \"clientFile\": {" + + " \"type\": \"string\"," + + " \"format\": \"dial-file-encoded\"," + + " \"dial:meta\": {" + + " \"dial:propertyKind\": \"client\"," + + " \"dial:propertyOrder\": 1" + + " }" + + " }" + + "}," + + "\"required\": [\"clientFile\"]" + + "}"; + when(application.getCustomAppSchemaId()).thenReturn(URI.create("schemaId")); + when(config.getCustomApplicationSchema(any())).thenReturn(schemaWithoutEndpoint); + + Assertions.assertThrows(ApplicationTypeSchemaProcessingException.class, () -> + ApplicationTypeSchemaUtils.modifyEndpointForCustomApplication(config, application)); + } + }