Skip to content

Commit

Permalink
align with PMD UnitTestShouldIncludeAssert
Browse files Browse the repository at this point in the history
  • Loading branch information
azakrzewski-hy committed Dec 19, 2024
1 parent 49c27b5 commit 64904cf
Showing 1 changed file with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,36 +78,60 @@ static void setUp()
@Test
void testRequestToPresignedUrls()
{
validateRequest("/rest/hxinsight/requests/get-presigned-urls.yml");
HxInsightRequest hxInsightRequest = RequestLoader.load("/rest/hxinsight/requests/get-presigned-urls.yml");

Request request = makeRequest(hxInsightRequest);

assertThat(openApiInteractionValidator.validateRequest(request).getMessages()).isEmpty();
}

@SneakyThrows
@Test
void testCreateRequestToIngestionEvents()
{
validateRequestWithSchema("/rest/hxinsight/requests/create-document.yml");
HxInsightRequest hxInsightRequest = RequestLoader.load("/rest/hxinsight/requests/create-document.yml");
JsonNode propertiesNode = new ObjectMapper().readTree(hxInsightRequest.body()).get(0).get("properties");

Request request = makeRequest(hxInsightRequest);

assertThat(openApiInteractionValidator.validateRequest(request).getMessages()).isEmpty();
assertThat(schemaValidator.validate(propertiesNode.toString(), propertiesSchema, null).getMessages()).isEmpty();
}

@SneakyThrows
@Test
void testUpdateRequestToIngestionEvents()
{
validateRequestWithSchema("/rest/hxinsight/requests/update-document.yml");
HxInsightRequest hxInsightRequest = RequestLoader.load("/rest/hxinsight/requests/update-document.yml");
JsonNode propertiesNode = new ObjectMapper().readTree(hxInsightRequest.body()).get(0).get("properties");

Request request = makeRequest(hxInsightRequest);

assertThat(openApiInteractionValidator.validateRequest(request).getMessages()).isEmpty();
assertThat(schemaValidator.validate(propertiesNode.toString(), propertiesSchema, null).getMessages()).isEmpty();
}

@Test
void testDeleteRequestToIngestionEvents()
{
validateRequest("/rest/hxinsight/requests/delete-document.yml");
HxInsightRequest hxInsightRequest = RequestLoader.load("/rest/hxinsight/requests/delete-document.yml");

Request request = makeRequest(hxInsightRequest);

assertThat(openApiInteractionValidator.validateRequest(request).getMessages()).isEmpty();
}

private static SchemaValidator createSchemaValidator(final String api)
{
ParseOptions parseOptions = new ParseOptions();
final ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
return new SchemaValidator(
new OpenAPIParser().readLocation(api, null, parseOptions).getOpenAPI(),
new MessageResolver(LevelResolver.create().withLevel(ADDITIONAL_PROPERTIES_KEY, ValidationReport.Level.IGNORE).build()));
new MessageResolver(
LevelResolver
.create()
.withLevel(ADDITIONAL_PROPERTIES_KEY, ValidationReport.Level.IGNORE)
.build()));
}

private static Request makeRequest(HxInsightRequest hxInsightRequest)
Expand All @@ -116,21 +140,4 @@ private static Request makeRequest(HxInsightRequest hxInsightRequest)
hxInsightRequest.headers().forEach(builder::withHeader);
return builder.withBody(hxInsightRequest.body()).build();
}

private static void validateRequest(String requestPath)
{
HxInsightRequest hxInsightRequest = RequestLoader.load(requestPath);
Request request = makeRequest(hxInsightRequest);
assertThat(openApiInteractionValidator.validateRequest(request).getMessages()).isEmpty();
}

@SneakyThrows
private static void validateRequestWithSchema(String requestPath)
{
HxInsightRequest hxInsightRequest = RequestLoader.load(requestPath);
JsonNode propertiesNode = new ObjectMapper().readTree(hxInsightRequest.body()).get(0).get("properties");
Request request = makeRequest(hxInsightRequest);
assertThat(openApiInteractionValidator.validateRequest(request).getMessages()).isEmpty();
assertThat(schemaValidator.validate(propertiesNode.toString(), propertiesSchema, null).getMessages()).isEmpty();
}
}

0 comments on commit 64904cf

Please sign in to comment.