Skip to content

Commit

Permalink
Fix pipeline test failure
Browse files Browse the repository at this point in the history
Attempting to fix a unit test failure that was only occurring when run
via GitHub Actions.
  • Loading branch information
kqarryzada committed Jul 22, 2024
1 parent c5a828d commit 1b4c1dd
Showing 1 changed file with 46 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -769,63 +769,75 @@ public void testPatchThroughScimInterface_typeId() throws ScimException

/**
* Test error response when invalid JSON is submitted.
*
* @throws ScimException if an error occurs.
*/
@Test
public void testInvalidJson() throws ScimException
public void testInvalidJson()
{
WebTarget target = target().register(
new JacksonJsonProvider(JsonUtils.createObjectMapper()));

Response response = target.path("SingletonUsers").request().
accept(MEDIA_TYPE_SCIM).post(
Entity.entity("{badJson}", MEDIA_TYPE_SCIM));
assertEquals(response.getStatus(), 400);
assertEquals(response.getMediaType(), MediaType.valueOf(MEDIA_TYPE_SCIM));
ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
assertEquals(errorResponse.getStatus(), Integer.valueOf(400));
assertEquals(errorResponse.getScimType(), "invalidSyntax");
assertNotNull(errorResponse.getDetail());
var request = target.path("SingletonUsers").request().
accept(MEDIA_TYPE_SCIM);

try (Response response = request.post(
Entity.entity("{badJson}", MEDIA_TYPE_SCIM)))
{
assertEquals(response.getStatus(), 400);
assertEquals(response.getMediaType(), MediaType.valueOf(MEDIA_TYPE_SCIM));
ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
assertEquals(errorResponse.getStatus(), Integer.valueOf(400));
assertEquals(errorResponse.getScimType(), "invalidSyntax");
assertNotNull(errorResponse.getDetail());
}

// Now with application/json
response = target.path("SingletonUsers").request().
request = target.path("SingletonUsers").request().
accept(MediaType.APPLICATION_JSON_TYPE,
ServerUtils.MEDIA_TYPE_SCIM_TYPE).post(
Entity.entity("{badJson}", MediaType.APPLICATION_JSON_TYPE));
assertEquals(response.getStatus(), 400);
assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
ServerUtils.MEDIA_TYPE_SCIM_TYPE);

try (Response response = request.post(
Entity.entity("{badJson}", MediaType.APPLICATION_JSON_TYPE)))
{
assertEquals(response.getStatus(), 400);
assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
}
}

/**
* Test error response when an invalid standard SCIM message is submitted and
* a Jackson binding error occurs.
*
* @throws ScimException if an error occurs.
*/
@Test
public void testInvalidMessage() throws ScimException
public void testInvalidMessage()
{
WebTarget target = target().register(
new JacksonJsonProvider(JsonUtils.createObjectMapper()));

Response response = target.path("SingletonUsers").path(".search").
request().accept(MEDIA_TYPE_SCIM).post(Entity.entity(
"{\"undefinedField\": \"value\"}", MEDIA_TYPE_SCIM));
assertEquals(response.getStatus(), 400);
assertEquals(response.getMediaType(), MediaType.valueOf(MEDIA_TYPE_SCIM));
ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
assertEquals(errorResponse.getStatus(), Integer.valueOf(400));
assertEquals(errorResponse.getScimType(), "invalidSyntax");
assertNotNull(errorResponse.getDetail());
var request = target.path("SingletonUsers").path(".search").
request().accept(MEDIA_TYPE_SCIM);

try (Response response = request.post(Entity.entity(
"{\"undefinedField\": \"value\"}", MEDIA_TYPE_SCIM)))
{
assertEquals(response.getStatus(), 400);
assertEquals(response.getMediaType(), MediaType.valueOf(MEDIA_TYPE_SCIM));
ErrorResponse errorResponse = response.readEntity(ErrorResponse.class);
assertEquals(errorResponse.getStatus(), Integer.valueOf(400));
assertEquals(errorResponse.getScimType(), "invalidSyntax");
assertNotNull(errorResponse.getDetail());
}

// Now with application/json
response = target.path("SingletonUsers").path(".search").
request = target.path("SingletonUsers").path(".search").
request().accept(MediaType.APPLICATION_JSON_TYPE,
ServerUtils.MEDIA_TYPE_SCIM_TYPE).post(Entity.entity(
"{\"undefinedField\": \"value\"}", MediaType.APPLICATION_JSON_TYPE));
assertEquals(response.getStatus(), 400);
assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
ServerUtils.MEDIA_TYPE_SCIM_TYPE);

try (Response response = request.post(Entity.entity(
"{\"undefinedField\": \"value\"}", MediaType.APPLICATION_JSON_TYPE)))
{
assertEquals(response.getStatus(), 400);
assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
}
}

/**
Expand Down

0 comments on commit 1b4c1dd

Please sign in to comment.