-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTestPatternResourcePutEnabledShould.java
More file actions
77 lines (66 loc) · 2.93 KB
/
TestPatternResourcePutEnabledShould.java
File metadata and controls
77 lines (66 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package org.finos.calm.resources;
import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import org.finos.calm.domain.exception.NamespaceNotFoundException;
import org.finos.calm.domain.Pattern;
import org.finos.calm.domain.exception.PatternNotFoundException;
import org.finos.calm.store.PatternStore;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.stream.Stream;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.Mockito.when;
@QuarkusTest
@ExtendWith(MockitoExtension.class)
@TestProfile(AllowPutProfile.class)
public class TestPatternResourcePutEnabledShould {
@InjectMock
PatternStore mockPatternStore;
static Stream<Arguments> provideParametersForPutPatternTests() {
return Stream.of(
Arguments.of(new NamespaceNotFoundException(), 404),
Arguments.of(new PatternNotFoundException(), 404),
Arguments.of(null, 201)
);
}
@ParameterizedTest
@MethodSource("provideParametersForPutPatternTests")
void respond_correctly_to_put_pattern_correctly(Throwable exceptionToThrow, int expectedStatusCode) throws PatternNotFoundException, NamespaceNotFoundException {
Pattern expectedPattern = new Pattern.PatternBuilder()
.setNamespace("test")
.setVersion("1.0.1")
.setPattern("{ \"test\": \"json\" }")
.setId(20)
.build();
System.out.println("TestPatterResourcePutEnabled mock: " + mockPatternStore);
if(exceptionToThrow != null) {
when(mockPatternStore.updatePatternForVersion(expectedPattern)).thenThrow(exceptionToThrow);
} else {
when(mockPatternStore.updatePatternForVersion(expectedPattern)).thenReturn(expectedPattern);
}
if(expectedStatusCode == 201) {
given()
.header("Content-Type", "application/json")
.body("{ \"test\": \"json\" }")
.when()
.put("/calm/namespaces/test/patterns/20/versions/1.0.1")
.then()
.statusCode(expectedStatusCode)
.header("Location", containsString("/calm/namespaces/test/patterns/20/versions/1.0.1"));
} else {
given()
.header("Content-Type", "application/json")
.body("{ \"test\": \"json\" }")
.when()
.put("/calm/namespaces/test/patterns/20/versions/1.0.1")
.then()
.statusCode(expectedStatusCode);
}
}
}