Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -47,7 +47,7 @@ void return_a_404_when_an_invalid_namespace_is_provided_on_get_architectures() t

@Test
void return_list_of_architecture_ids_when_valid_namespace_provided_on_get_architectures() throws NamespaceNotFoundException {
when(mockArchitectureStore.getArchitecturesForNamespace(anyString())).thenReturn(Arrays.asList(12345,54321));
when(mockArchitectureStore.getArchitecturesForNamespace(anyString())).thenReturn(Arrays.asList(12345, 54321));

given()
.when()
Expand All @@ -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,23 +127,23 @@ 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) {
if(exceptionToThrow != null) {
when(mockArchitectureStore.getArchitectureVersions(any(Architecture.class))).thenThrow(exceptionToThrow);
} else {
when(mockArchitectureStore.getArchitectureVersions(any(Architecture.class))).thenReturn(versions);
}

if (expectedStatusCode == 200 ) {
if(expectedStatusCode == 200) {
String expectedBody = "{\"values\":[\"1.0.0\",\"1.0.1\"]}";
given()
.when()
Expand Down Expand Up @@ -174,24 +174,24 @@ 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 {
if (exceptionToThrow != null) {
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 {
String architecture = "{ \"test\": \"json\" }";
when(mockArchitectureStore.getArchitectureForVersion(any(Architecture.class))).thenReturn(architecture);
}

if (expectedStatusCode == 200) {
if(expectedStatusCode == 200) {
given()
.when()
.get("/calm/namespaces/" + namespace + "/architectures/12/versions/1.0.0")
Expand All @@ -211,24 +211,24 @@ 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")
.setArchitecture("{ \"test\": \"json\" }")
.setId(20)
.build();

if (exceptionToThrow != null) {
if(exceptionToThrow != null) {
when(mockArchitectureStore.createArchitectureForVersion(expectedArchitecture)).thenThrow(exceptionToThrow);
} else {
when(mockArchitectureStore.createArchitectureForVersion(expectedArchitecture)).thenReturn(expectedArchitecture);
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 All @@ -50,13 +49,13 @@ void respond_correctly_to_put_pattern_correctly(Class<? extends Exception> excep

System.out.println("TestPatterResourcePutEnabled mock: " + mockPatternStore);

if (exceptionToThrow != null) {
if(exceptionToThrow != null) {
when(mockPatternStore.updatePatternForVersion(expectedPattern)).thenThrow(exceptionToThrow);
} else {
when(mockPatternStore.updatePatternForVersion(expectedPattern)).thenReturn(expectedPattern);
}

if (expectedStatusCode == 201) {
if(expectedStatusCode == 201) {
given()
.header("Content-Type", "application/json")
.body("{ \"test\": \"json\" }")
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 All @@ -47,7 +47,7 @@ void return_a_404_when_an_invalid_namespace_is_provided_on_get_patterns() throws

@Test
void return_list_of_pattern_ids_when_valid_namespace_provided_on_get_patterns() throws NamespaceNotFoundException {
when(mockPatternStore.getPatternsForNamespace(anyString())).thenReturn(Arrays.asList(12345,54321));
when(mockPatternStore.getPatternsForNamespace(anyString())).thenReturn(Arrays.asList(12345, 54321));

given()
.when()
Expand All @@ -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,23 +127,23 @@ 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) {
if(exceptionToThrow != null) {
when(mockPatternStore.getPatternVersions(any(Pattern.class))).thenThrow(exceptionToThrow);
} else {
when(mockPatternStore.getPatternVersions(any(Pattern.class))).thenReturn(versions);
}

if (expectedStatusCode == 200 ) {
if(expectedStatusCode == 200) {
String expectedBody = "{\"values\":[\"1.0.0\",\"1.0.1\"]}";
given()
.when()
Expand Down Expand Up @@ -174,24 +174,24 @@ 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 {
if (exceptionToThrow != null) {
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 {
String pattern = "{ \"test\": \"json\" }";
when(mockPatternStore.getPatternForVersion(any(Pattern.class))).thenReturn(pattern);
}

if (expectedStatusCode == 200) {
if(expectedStatusCode == 200) {
given()
.when()
.get("/calm/namespaces/" + namespace + "/patterns/12/versions/1.0.0")
Expand All @@ -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 All @@ -230,7 +230,7 @@ void respond_correctly_to_create_pattern_correctly(Class<? extends Exception> ex

System.out.println("TestPatternResourceShould mock: " + mockPatternStore);

if (exceptionToThrow != null) {
if(exceptionToThrow != null) {
when(mockPatternStore.createPatternForVersion(expectedPattern)).thenThrow(exceptionToThrow);
} else {
when(mockPatternStore.createPatternForVersion(expectedPattern)).thenReturn(expectedPattern);
Expand Down