generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Propagate more errors to the client side
This commit improves error reporting on the client side. It propagates some errors which were previously only captured on the server side. In particular, it will now: - report which property was being resolved, instead of showing internal `auto.test.resources` properties - capture errors which are sent by the server but were dropped because of lack of JSON error handling - report when a container cannot be started or failed during startup - provide clearer message when the test resources service is down Fixes #444
- Loading branch information
Showing
18 changed files
with
279 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...esources-client/src/main/java/io/micronaut/testresources/client/SimpleJsonErrorModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2017-2023 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.testresources.client; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.micronaut.serde.annotation.Serdeable; | ||
|
||
import java.util.List; | ||
|
||
@Serdeable | ||
public record SimpleJsonErrorModel( | ||
@JsonProperty("message") String message, | ||
@JsonProperty("_embedded") Embedded embedded | ||
) { | ||
@Serdeable | ||
public record Embedded( | ||
@JsonProperty("errors") List<SimpleJsonErrorModel> errors | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
.../src/test/groovy/io/micronaut/testresources/client/NoServerTestResourcesClientTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.micronaut.testresources.client | ||
|
||
import io.micronaut.context.ApplicationContext | ||
import io.micronaut.test.extensions.spock.annotation.MicronautTest | ||
import spock.lang.Specification | ||
import spock.util.environment.RestoreSystemProperties | ||
|
||
import static io.micronaut.testresources.client.ConfigFinder.systemPropertyNameOf | ||
|
||
@MicronautTest | ||
class NoServerTestResourcesClientTest extends Specification implements ClientCleanup { | ||
|
||
private static final String DUMMY_URL = "https://localhost:666/nope" | ||
|
||
@RestoreSystemProperties | ||
def "reasonable error message if the server isn't running"() { | ||
|
||
when: | ||
createApplication() | ||
|
||
then: | ||
TestResourcesException e = thrown() | ||
e.message == "Test resource service is not available at $DUMMY_URL" | ||
} | ||
|
||
private ApplicationContext createApplication() { | ||
System.setProperty(systemPropertyNameOf(TestResourcesClient.SERVER_URI), DUMMY_URL) | ||
def app = ApplicationContext.builder() | ||
.properties(['server': 'false']) | ||
.start() | ||
assert !app.findBean(TestServer).present | ||
return app | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...-core/src/main/java/io/micronaut/testresources/core/TestResourcesResolutionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2017-2021 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.testresources.core; | ||
|
||
/** | ||
* An exception thrown whenever test resources was expected to resolve | ||
* a property but couldn't. | ||
*/ | ||
public class TestResourcesResolutionException extends RuntimeException { | ||
public TestResourcesResolutionException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public TestResourcesResolutionException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public TestResourcesResolutionException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.