Skip to content

Commit

Permalink
more CustomApplicationTypeSchemaUtils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-zinchenko committed Dec 26, 2024
1 parent a358f4a commit 2baa10f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}

}

0 comments on commit 2baa10f

Please sign in to comment.