Skip to content

Commit

Permalink
Fix tests to allow all tests to run as part of suite (finos#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
grahampacker-ms committed Jan 1, 2025
1 parent 88a295d commit 50e1957
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TestArchitectureResourceShould {

@Test
void return_a_404_when_an_invalid_namespace_is_provided_on_get_architectures() throws NamespaceNotFoundException {
when(mockArchitectureStore.getArchitecturesForNamespace(anyString())).thenThrow(NamespaceNotFoundException.class);
when(mockArchitectureStore.getArchitecturesForNamespace(anyString())).thenThrow(new NamespaceNotFoundException());

given()
.when()
Expand Down Expand Up @@ -62,7 +62,7 @@ void return_list_of_architecture_ids_when_valid_namespace_provided_on_get_archit
@Test
void return_a_404_when_invalid_namespace_is_provided_on_create_architecture() throws NamespaceNotFoundException {
when(mockArchitectureStore.createArchitectureForNamespace(any(Architecture.class)))
.thenThrow(NamespaceNotFoundException.class);
.thenThrow(new NamespaceNotFoundException());

String architecture = "{ \"test\": \"json\" }";

Expand Down Expand Up @@ -127,15 +127,15 @@ private void verifyExpectedArchitectureForVersions(String namespace) throws Name

static Stream<Arguments> provideParametersForArchitectureVersionTests() {
return Stream.of(
Arguments.of("invalid", NamespaceNotFoundException.class, 404),
Arguments.of("valid", ArchitectureNotFoundException.class, 404),
Arguments.of("invalid", new NamespaceNotFoundException(), 404),
Arguments.of("valid", new ArchitectureNotFoundException(), 404),
Arguments.of("valid", null, 200)
);
}

@ParameterizedTest
@MethodSource("provideParametersForArchitectureVersionTests")
void respond_correctly_to_get_architecture_versions_query(String namespace, Class<? extends Exception> exceptionToThrow, int expectedStatusCode) throws ArchitectureNotFoundException, NamespaceNotFoundException {
void respond_correctly_to_get_architecture_versions_query(String namespace, Throwable exceptionToThrow, int expectedStatusCode) throws ArchitectureNotFoundException, NamespaceNotFoundException {
var versions = List.of("1.0.0", "1.0.1");
if (exceptionToThrow != null) {
when(mockArchitectureStore.getArchitectureVersions(any(Architecture.class))).thenThrow(exceptionToThrow);
Expand Down Expand Up @@ -174,16 +174,16 @@ private void verifyExpectedGetArchitecture(String namespace) throws Architecture

static Stream<Arguments> provideParametersForGetArchitectureTests() {
return Stream.of(
Arguments.of("invalid", NamespaceNotFoundException.class, 404),
Arguments.of("valid", ArchitectureNotFoundException.class, 404),
Arguments.of("valid", ArchitectureVersionNotFoundException.class, 404),
Arguments.of("invalid", new NamespaceNotFoundException(), 404),
Arguments.of("valid", new ArchitectureNotFoundException(), 404),
Arguments.of("valid", new ArchitectureVersionNotFoundException(), 404),
Arguments.of("valid", null, 200)
);
}

@ParameterizedTest
@MethodSource("provideParametersForGetArchitectureTests")
void respond_correctly_to_get_architecture_for_a_specific_version_correctly(String namespace, Class<? extends Exception> exceptionToThrow, int expectedStatusCode) throws ArchitectureVersionNotFoundException, ArchitectureNotFoundException, NamespaceNotFoundException {
void respond_correctly_to_get_architecture_for_a_specific_version_correctly(String namespace, Throwable exceptionToThrow, int expectedStatusCode) throws ArchitectureVersionNotFoundException, ArchitectureNotFoundException, NamespaceNotFoundException {
if (exceptionToThrow != null) {
when(mockArchitectureStore.getArchitectureForVersion(any(Architecture.class))).thenThrow(exceptionToThrow);
} else {
Expand Down Expand Up @@ -211,16 +211,16 @@ void respond_correctly_to_get_architecture_for_a_specific_version_correctly(Stri

static Stream<Arguments> provideParametersForCreateArchitectureTests() {
return Stream.of(
Arguments.of( NamespaceNotFoundException.class, 404),
Arguments.of( ArchitectureNotFoundException.class, 404),
Arguments.of(ArchitectureVersionExistsException.class, 409),
Arguments.of( new NamespaceNotFoundException(), 404),
Arguments.of( new ArchitectureNotFoundException(), 404),
Arguments.of(new ArchitectureVersionExistsException(), 409),
Arguments.of(null, 201)
);
}

@ParameterizedTest
@MethodSource("provideParametersForCreateArchitectureTests")
void respond_correctly_to_create_architecture(Class<? extends Exception> exceptionToThrow, int expectedStatusCode) throws ArchitectureNotFoundException, ArchitectureVersionExistsException, NamespaceNotFoundException {
void respond_correctly_to_create_architecture(Throwable exceptionToThrow, int expectedStatusCode) throws ArchitectureNotFoundException, ArchitectureVersionExistsException, NamespaceNotFoundException {
Architecture expectedArchitecture = new Architecture.ArchitectureBuilder()
.setNamespace("test")
.setVersion("1.0.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,22 @@
@QuarkusTest
@ExtendWith(MockitoExtension.class)
@TestProfile(AllowPutProfile.class)
@Disabled("This test fails due to a multiple injection problem with a conflicting mock in TestPatternResourceShould, will need to find a fix. (the tests do pass)")
public class TestPatternResourcePutEnabledShould {

@InjectMock
PatternStore mockPatternStore;

static Stream<Arguments> provideParametersForPutPatternTests() {
return Stream.of(
Arguments.of( NamespaceNotFoundException.class, 404),
Arguments.of( PatternNotFoundException.class, 404),
Arguments.of( new NamespaceNotFoundException(), 404),
Arguments.of( new PatternNotFoundException(), 404),
Arguments.of(null, 201)
);
}

@ParameterizedTest
@MethodSource("provideParametersForPutPatternTests")
void respond_correctly_to_put_pattern_correctly(Class<? extends Exception> exceptionToThrow, int expectedStatusCode) throws PatternNotFoundException, NamespaceNotFoundException {
void respond_correctly_to_put_pattern_correctly(Throwable exceptionToThrow, int expectedStatusCode) throws PatternNotFoundException, NamespaceNotFoundException {

Pattern expectedPattern = new Pattern.PatternBuilder()
.setNamespace("test")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class TestPatternResourceShould {

@Test
void return_a_404_when_an_invalid_namespace_is_provided_on_get_patterns() throws NamespaceNotFoundException {
when(mockPatternStore.getPatternsForNamespace(anyString())).thenThrow(NamespaceNotFoundException.class);
when(mockPatternStore.getPatternsForNamespace(anyString())).thenThrow(new NamespaceNotFoundException());

given()
.when()
Expand Down Expand Up @@ -62,7 +62,7 @@ void return_list_of_pattern_ids_when_valid_namespace_provided_on_get_patterns()
@Test
void return_a_404_when_invalid_namespace_is_provided_on_create_pattern() throws NamespaceNotFoundException {
when(mockPatternStore.createPatternForNamespace(any(Pattern.class)))
.thenThrow(NamespaceNotFoundException.class);
.thenThrow(new NamespaceNotFoundException());

String pattern = "{ \"test\": \"json\" }";

Expand Down Expand Up @@ -127,15 +127,15 @@ private void verifyExpectedPatternForVersions(String namespace) throws PatternNo

static Stream<Arguments> provideParametersForPatternVersionTests() {
return Stream.of(
Arguments.of("invalid", NamespaceNotFoundException.class, 404),
Arguments.of("valid", PatternNotFoundException.class, 404),
Arguments.of("invalid", new NamespaceNotFoundException(), 404),
Arguments.of("valid", new PatternNotFoundException(), 404),
Arguments.of("valid", null, 200)
);
}

@ParameterizedTest
@MethodSource("provideParametersForPatternVersionTests")
void respond_correctly_to_get_pattern_versions_query(String namespace, Class<? extends Exception> exceptionToThrow, int expectedStatusCode) throws PatternNotFoundException, NamespaceNotFoundException {
void respond_correctly_to_get_pattern_versions_query(String namespace, Throwable exceptionToThrow, int expectedStatusCode) throws PatternNotFoundException, NamespaceNotFoundException {
var versions = List.of("1.0.0", "1.0.1");
if (exceptionToThrow != null) {
when(mockPatternStore.getPatternVersions(any(Pattern.class))).thenThrow(exceptionToThrow);
Expand Down Expand Up @@ -174,16 +174,16 @@ private void verifyExpectedGetPattern(String namespace) throws PatternNotFoundEx

static Stream<Arguments> provideParametersForGetPatternTests() {
return Stream.of(
Arguments.of("invalid", NamespaceNotFoundException.class, 404),
Arguments.of("valid", PatternNotFoundException.class, 404),
Arguments.of("valid", PatternVersionNotFoundException.class, 404),
Arguments.of("invalid", new NamespaceNotFoundException(), 404),
Arguments.of("valid", new PatternNotFoundException(), 404),
Arguments.of("valid", new PatternVersionNotFoundException(), 404),
Arguments.of("valid", null, 200)
);
}

@ParameterizedTest
@MethodSource("provideParametersForGetPatternTests")
void respond_correct_to_get_pattern_for_a_specific_version_correctly(String namespace, Class<? extends Exception> exceptionToThrow, int expectedStatusCode) throws PatternNotFoundException, NamespaceNotFoundException, PatternVersionNotFoundException {
void respond_correct_to_get_pattern_for_a_specific_version_correctly(String namespace, Throwable exceptionToThrow, int expectedStatusCode) throws PatternNotFoundException, NamespaceNotFoundException, PatternVersionNotFoundException {
if (exceptionToThrow != null) {
when(mockPatternStore.getPatternForVersion(any(Pattern.class))).thenThrow(exceptionToThrow);
} else {
Expand Down Expand Up @@ -211,16 +211,16 @@ void respond_correct_to_get_pattern_for_a_specific_version_correctly(String name

static Stream<Arguments> provideParametersForCreatePatternTests() {
return Stream.of(
Arguments.of( NamespaceNotFoundException.class, 404),
Arguments.of( PatternNotFoundException.class, 404),
Arguments.of(PatternVersionExistsException.class, 409),
Arguments.of( new NamespaceNotFoundException(), 404),
Arguments.of( new PatternNotFoundException(), 404),
Arguments.of(new PatternVersionExistsException(), 409),
Arguments.of(null, 201)
);
}

@ParameterizedTest
@MethodSource("provideParametersForCreatePatternTests")
void respond_correctly_to_create_pattern_correctly(Class<? extends Exception> exceptionToThrow, int expectedStatusCode) throws PatternNotFoundException, PatternVersionExistsException, NamespaceNotFoundException {
void respond_correctly_to_create_pattern_correctly(Throwable exceptionToThrow, int expectedStatusCode) throws PatternNotFoundException, PatternVersionExistsException, NamespaceNotFoundException {
Pattern expectedPattern = new Pattern.PatternBuilder()
.setNamespace("test")
.setVersion("1.0.1")
Expand Down

0 comments on commit 50e1957

Please sign in to comment.