|
6 | 6 | import dev.dochia.cli.core.playbook.executor.SimpleExecutor; |
7 | 7 | import dev.dochia.cli.core.report.TestCaseListener; |
8 | 8 | import dev.dochia.cli.core.report.TestReportsGenerator; |
| 9 | +import dev.dochia.cli.core.util.KeyValuePair; |
9 | 10 | import io.quarkus.test.junit.QuarkusTest; |
10 | 11 | import io.quarkus.test.junit.mockito.InjectSpy; |
11 | 12 | import io.swagger.v3.oas.models.Operation; |
@@ -57,7 +58,12 @@ void givenAGetOperationImplemented_whenCallingTheHttpMethodsPlaybook_thenResults |
57 | 58 | @Test |
58 | 59 | void givenAnOperation_whenCallingTheHttpMethodsPlaybook_thenResultsAreCorrectlyReported() { |
59 | 60 | PlaybookData data = PlaybookData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).requestContentTypes(List.of("application/json")).build(); |
60 | | - HttpResponse httpResponse = HttpResponse.builder().body("{}").responseCode(405).httpMethod("POST").build(); |
| 61 | + HttpResponse httpResponse = HttpResponse.builder() |
| 62 | + .body("{}") |
| 63 | + .responseCode(405) |
| 64 | + .httpMethod("POST") |
| 65 | + .headers(List.of(new KeyValuePair<>("Allow", "GET, PUT, DELETE"))) |
| 66 | + .build(); |
61 | 67 | Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(httpResponse); |
62 | 68 |
|
63 | 69 | httpMethodsPlaybook.run(data); |
@@ -100,4 +106,59 @@ void shouldNotRunSamePathTwice() { |
100 | 106 | httpMethodsPlaybook.run(data); |
101 | 107 | Mockito.verify(testCaseListener, Mockito.times(7)).reportResultError(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString(), AdditionalMatchers.aryEq(new Object[]{"POST", 405, 200})); |
102 | 108 | } |
| 109 | + |
| 110 | + @Test |
| 111 | + void givenAnOperation_whenCallingTheHttpMethodsPlaybookAndTheServiceResponsesWithNon2xxNon405_thenWarningIsReported() { |
| 112 | + PlaybookData data = PlaybookData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).requestContentTypes(List.of("application/json")).build(); |
| 113 | + HttpResponse httpResponse = HttpResponse.builder().body("{}").responseCode(500).httpMethod("POST").build(); |
| 114 | + Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(httpResponse); |
| 115 | + |
| 116 | + httpMethodsPlaybook.run(data); |
| 117 | + Mockito.verify(testCaseListener, Mockito.times(7)).reportResultWarn(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString(), AdditionalMatchers.aryEq(new Object[]{"POST", 405, 500})); |
| 118 | + } |
| 119 | + |
| 120 | + @Test |
| 121 | + void givenAnOperation_whenCallingTheHttpMethodsPlaybookAndTheServiceResponsesWith405ButMissingAllowHeader_thenWarningIsReported() { |
| 122 | + PlaybookData data = PlaybookData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).requestContentTypes(List.of("application/json")).build(); |
| 123 | + HttpResponse httpResponse = HttpResponse.builder() |
| 124 | + .body("{}") |
| 125 | + .responseCode(405) |
| 126 | + .httpMethod("POST") |
| 127 | + .headers(List.of()) |
| 128 | + .build(); |
| 129 | + Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(httpResponse); |
| 130 | + |
| 131 | + httpMethodsPlaybook.run(data); |
| 132 | + Mockito.verify(testCaseListener, Mockito.times(7)).reportResultWarn(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.eq("POST"), AdditionalMatchers.aryEq(new Object[]{405})); |
| 133 | + } |
| 134 | + |
| 135 | + @Test |
| 136 | + void givenAnOperation_whenCallingTheHttpMethodsPlaybookAndTheServiceResponsesWith405AndAllowHeaderContainsMethod_thenWarningIsReported() { |
| 137 | + PlaybookData data = PlaybookData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).requestContentTypes(List.of("application/json")).build(); |
| 138 | + HttpResponse httpResponse = HttpResponse.builder() |
| 139 | + .body("{}") |
| 140 | + .responseCode(405) |
| 141 | + .httpMethod("POST") |
| 142 | + .headers(List.of(new KeyValuePair<>("Allow", "GET, POST, PUT"))) |
| 143 | + .build(); |
| 144 | + Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(httpResponse); |
| 145 | + |
| 146 | + httpMethodsPlaybook.run(data); |
| 147 | + Mockito.verify(testCaseListener, Mockito.times(7)).reportResultWarn(Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.eq("POST"), AdditionalMatchers.aryEq(new Object[]{405, "POST"})); |
| 148 | + } |
| 149 | + |
| 150 | + @Test |
| 151 | + void givenAnOperation_whenCallingTheHttpMethodsPlaybookAndTheServiceResponsesWith405AndValidAllowHeader_thenInfoIsReported() { |
| 152 | + PlaybookData data = PlaybookData.builder().pathItem(new PathItem()).reqSchema(new StringSchema()).requestContentTypes(List.of("application/json")).build(); |
| 153 | + HttpResponse httpResponse = HttpResponse.builder() |
| 154 | + .body("{}") |
| 155 | + .responseCode(405) |
| 156 | + .httpMethod("POST") |
| 157 | + .headers(List.of(new KeyValuePair<>("Allow", "GET, PUT, DELETE"))) |
| 158 | + .build(); |
| 159 | + Mockito.when(serviceCaller.call(Mockito.any())).thenReturn(httpResponse); |
| 160 | + |
| 161 | + httpMethodsPlaybook.run(data); |
| 162 | + Mockito.verify(testCaseListener, Mockito.times(7)).reportResultInfo(Mockito.any(), Mockito.any(), Mockito.anyString(), AdditionalMatchers.aryEq(new Object[]{"POST", 405})); |
| 163 | + } |
103 | 164 | } |
0 commit comments