Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Update Quarkus' TestNessieError #6399

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@
*/
package org.projectnessie.server.error;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import java.net.URI;
import javax.ws.rs.core.Response;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -53,6 +50,15 @@
@ExtendWith(QuarkusNessieClientResolver.class)
class TestNessieError {

// Cannot use @ExtendWith(SoftAssertionsExtension.class) + @InjectSoftAssertions here, because
// of Quarkus class loading issues. See https://github.com/quarkusio/quarkus/issues/19814
protected final SoftAssertions soft = new SoftAssertions();

@AfterEach
public void afterEachAssert() {
soft.assertAll();
}

private static HttpClient client;

@BeforeAll
Expand All @@ -71,117 +77,80 @@ static void setup(@NessieClientUri URI uri) {

@Test
void nullParameterQueryGet() {
assertThatThrownBy(() -> client.newRequest().path("nullParameterQueryGet").get())
soft.assertThatThrownBy(() -> client.newRequest().path("nullParameterQueryGet").get())
.isInstanceOf(NessieBadRequestException.class)
.hasMessage("Bad Request (HTTP/400): nullParameterQueryGet.hash: must not be null");
}

@Test
void nullParameterQueryPost() {
assertThatThrownBy(() -> client.newRequest().path("nullParameterQueryPost").post(""))
soft.assertThatThrownBy(() -> client.newRequest().path("nullParameterQueryPost").post(""))
.isInstanceOf(NessieBadRequestException.class)
.hasMessage("Bad Request (HTTP/400): nullParameterQueryPost.hash: must not be null");
}

@Test
void emptyParameterQueryGet() {
assertAll(
() ->
assertThatThrownBy(() -> client.newRequest().path("emptyParameterQueryGet").get())
.isInstanceOf(NessieBadRequestException.class)
.hasMessage(
"Bad Request (HTTP/400): emptyParameterQueryGet.hash: must not be empty"),
() ->
assertThatThrownBy(
() ->
client
.newRequest()
.path("emptyParameterQueryGet")
.queryParam("hash", "")
.get())
.isInstanceOf(NessieBadRequestException.class)
.hasMessage(
"Bad Request (HTTP/400): emptyParameterQueryGet.hash: must not be empty"));
soft.assertThatThrownBy(() -> client.newRequest().path("emptyParameterQueryGet").get())
.isInstanceOf(NessieBadRequestException.class)
.hasMessage("Bad Request (HTTP/400): emptyParameterQueryGet.hash: must not be empty");
soft.assertThatThrownBy(
() -> client.newRequest().path("emptyParameterQueryGet").queryParam("hash", "").get())
.isInstanceOf(NessieBadRequestException.class)
.hasMessage("Bad Request (HTTP/400): emptyParameterQueryGet.hash: must not be empty");
}

@Test
void blankParameterQueryGet() {
assertAll(
() ->
assertThatThrownBy(() -> client.newRequest().path("blankParameterQueryGet").get())
.isInstanceOf(NessieBadRequestException.class)
.hasMessage(
"Bad Request (HTTP/400): blankParameterQueryGet.hash: must not be blank"),
() ->
assertThatThrownBy(
() ->
client
.newRequest()
.path("blankParameterQueryGet")
.queryParam("hash", "")
.get())
.isInstanceOf(NessieBadRequestException.class)
.hasMessage(
"Bad Request (HTTP/400): blankParameterQueryGet.hash: must not be blank"),
() ->
assertThatThrownBy(
() ->
client
.newRequest()
.path("blankParameterQueryGet")
.queryParam("hash", " ")
.get())
.isInstanceOf(NessieBadRequestException.class)
.hasMessage(
"Bad Request (HTTP/400): blankParameterQueryGet.hash: must not be blank"));
soft.assertThatThrownBy(() -> client.newRequest().path("blankParameterQueryGet").get())
.isInstanceOf(NessieBadRequestException.class)
.hasMessage("Bad Request (HTTP/400): blankParameterQueryGet.hash: must not be blank");
soft.assertThatThrownBy(
() -> client.newRequest().path("blankParameterQueryGet").queryParam("hash", "").get())
.isInstanceOf(NessieBadRequestException.class)
.hasMessage("Bad Request (HTTP/400): blankParameterQueryGet.hash: must not be blank");
soft.assertThatThrownBy(
() ->
client.newRequest().path("blankParameterQueryGet").queryParam("hash", " ").get())
.isInstanceOf(NessieBadRequestException.class)
.hasMessage("Bad Request (HTTP/400): blankParameterQueryGet.hash: must not be blank");
}

@Test
void unsupportedMediaTypePut() {
assertAll(
() ->
assertThatThrownBy(
() ->
unwrap(
() -> client.newRequest().path("unsupportedMediaTypePut").put("foo")))
.isInstanceOf(NessieUnsupportedMediaTypeException.class)
.hasMessage(
"Unsupported Media Type (HTTP/415): RESTEASY003065: Cannot consume content type"));
soft.assertThatThrownBy(
() -> unwrap(() -> client.newRequest().path("unsupportedMediaTypePut").put("foo")))
.isInstanceOf(NessieUnsupportedMediaTypeException.class)
.hasMessage(
"Unsupported Media Type (HTTP/415): RESTEASY003065: Cannot consume content type");
}

@Test
void entityValueViolation() {
assertAll(
() ->
assertThatThrownBy(
() -> client.newRequest().path("basicEntity").put("not really valid json"))
.isInstanceOf(NessieBadRequestException.class)
.hasMessageStartingWith(
"Bad Request (HTTP/400): Unrecognized token 'not': was expecting (JSON String, Number, "
+ "Array, Object or token 'null', 'true' or 'false')\n"),
() ->
assertThatThrownBy(() -> client.newRequest().path("basicEntity").put("{}"))
.isInstanceOf(NessieBadRequestException.class)
.hasMessageStartingWith(
"Bad Request (HTTP/400): Missing required creator property 'value' (index 0)\n"),
() ->
assertThatThrownBy(
() -> client.newRequest().path("basicEntity").put("{\"value\":null}"))
.isInstanceOf(NessieBadRequestException.class)
.hasMessageStartingWith(
"Bad Request (HTTP/400): basicEntity.entity.value: must not be null"),
() ->
assertThatThrownBy(
() -> client.newRequest().path("basicEntity").put("{\"value\":1.234}"))
.isInstanceOf(NessieBadRequestException.class)
.hasMessage(
"Bad Request (HTTP/400): basicEntity.entity.value: must be greater than or equal to 3"));
soft.assertThatThrownBy(
() -> client.newRequest().path("basicEntity").put("not really valid json"))
.isInstanceOf(NessieBadRequestException.class)
.hasMessageStartingWith(
"Bad Request (HTTP/400): Unrecognized token 'not': was expecting (JSON String, Number, "
+ "Array, Object or token 'null', 'true' or 'false')\n");
soft.assertThatThrownBy(() -> client.newRequest().path("basicEntity").put("{}"))
.isInstanceOf(NessieBadRequestException.class)
.hasMessageStartingWith(
"Bad Request (HTTP/400): Missing required creator property 'value' (index 0)\n");
soft.assertThatThrownBy(() -> client.newRequest().path("basicEntity").put("{\"value\":null}"))
.isInstanceOf(NessieBadRequestException.class)
.hasMessageStartingWith(
"Bad Request (HTTP/400): basicEntity.entity.value: must not be null");
soft.assertThatThrownBy(() -> client.newRequest().path("basicEntity").put("{\"value\":1.234}"))
.isInstanceOf(NessieBadRequestException.class)
.hasMessage(
"Bad Request (HTTP/400): basicEntity.entity.value: must be greater than or equal to 3");
}

@Test
void brokenEntitySerialization() {
// send something that cannot be deserialized
assertThatThrownBy(
soft.assertThatThrownBy(
() -> unwrap(() -> client.newRequest().path("basicEntity").put(new OtherEntity("bar"))))
.isInstanceOf(NessieBadRequestException.class)
.hasMessageStartingWith(
Expand All @@ -190,49 +159,41 @@ void brokenEntitySerialization() {

@Test
void nessieNotFoundException() {
NessieNotFoundException ex =
assertThrows(
NessieNotFoundException.class,
() -> unwrap(() -> client.newRequest().path("nessieNotFound").get()));
assertAll(
() -> assertEquals("not-there-message", ex.getMessage()),
() -> assertNull(ex.getServerStackTrace()),
() -> assertEquals(Response.Status.NOT_FOUND.getStatusCode(), ex.getStatus()));
soft.assertThatThrownBy(() -> unwrap(() -> client.newRequest().path("nessieNotFound").get()))
.isInstanceOf(NessieNotFoundException.class)
.hasMessage("not-there-message")
.asInstanceOf(InstanceOfAssertFactories.type(NessieNotFoundException.class))
.matches(e -> e.getServerStackTrace() == null)
.extracting(NessieNotFoundException::getStatus)
.isEqualTo(Response.Status.NOT_FOUND.getStatusCode());
}

@Test
void nonConstraintValidationExceptions() {
// Exceptions that trigger the "else-ish" part in ResteasyExceptionMapper.toResponse()

assertAll(
() ->
assertThatThrownBy(
() ->
unwrap(
() -> client.newRequest().path("constraintDefinitionException").get()))
.isInstanceOf(NessieInternalServerException.class)
.hasMessage(
"Internal Server Error (HTTP/500): javax.validation.ConstraintDefinitionException: meep"),
() ->
assertThatThrownBy(
() ->
unwrap(
() -> client.newRequest().path("constraintDeclarationException").get()))
.isInstanceOf(NessieInternalServerException.class)
.hasMessage(
"Internal Server Error (HTTP/500): javax.validation.ConstraintDeclarationException: meep"),
() ->
assertThatThrownBy(
() -> unwrap(() -> client.newRequest().path("groupDefinitionException").get()))
.isInstanceOf(NessieInternalServerException.class)
.hasMessage(
"Internal Server Error (HTTP/500): javax.validation.GroupDefinitionException: meep"));
soft.assertThatThrownBy(
() -> unwrap(() -> client.newRequest().path("constraintDefinitionException").get()))
.isInstanceOf(NessieInternalServerException.class)
.hasMessage(
"Internal Server Error (HTTP/500): javax.validation.ConstraintDefinitionException: meep");
soft.assertThatThrownBy(
() -> unwrap(() -> client.newRequest().path("constraintDeclarationException").get()))
.isInstanceOf(NessieInternalServerException.class)
.hasMessage(
"Internal Server Error (HTTP/500): javax.validation.ConstraintDeclarationException: meep");
soft.assertThatThrownBy(
() -> unwrap(() -> client.newRequest().path("groupDefinitionException").get()))
.isInstanceOf(NessieInternalServerException.class)
.hasMessage(
"Internal Server Error (HTTP/500): javax.validation.GroupDefinitionException: meep");
}

@Test
void unhandledRuntimeExceptionInStore() {
// see org.projectnessie.server.error.ErrorTestService.unhandledExceptionInTvsStore
assertThatThrownBy(() -> client.newRequest().path("unhandledExceptionInTvsStore/runtime").get())
soft.assertThatThrownBy(
() -> client.newRequest().path("unhandledExceptionInTvsStore/runtime").get())
.isInstanceOf(NessieInternalServerException.class)
.hasMessage(
"Internal Server Error (HTTP/500): java.lang.RuntimeException: Store.getValues-throwing");
Expand All @@ -241,7 +202,7 @@ void unhandledRuntimeExceptionInStore() {
@Test
void backendThrottledExceptionInStore() {
// see org.projectnessie.server.error.ErrorTestService.unhandledExceptionInTvsStore
assertThatThrownBy(
soft.assertThatThrownBy(
() -> client.newRequest().path("unhandledExceptionInTvsStore/throttle").get())
.isInstanceOf(NessieBackendThrottledException.class)
.hasMessage(
Expand Down