|
19 | 19 | import static org.assertj.core.api.Assertions.assertThat;
|
20 | 20 | import org.junit.jupiter.api.BeforeEach;
|
21 | 21 | import org.junit.jupiter.api.Test;
|
| 22 | +import org.assertj.core.api.Assertions; |
| 23 | +import org.operaton.connect.ConnectorRequestException; |
22 | 24 | import org.operaton.connect.httpclient.impl.HttpConnectorImpl;
|
23 | 25 | import org.operaton.connect.impl.DebugRequestInterceptor;
|
24 | 26 |
|
@@ -88,4 +90,84 @@ protected HttpResponse getResponse() {
|
88 | 90 | return connector.createRequest().url("http://operaton.com").get().execute();
|
89 | 91 | }
|
90 | 92 |
|
| 93 | + @Test |
| 94 | + public void testSuccessfulResponseCode() { |
| 95 | + // given |
| 96 | + testResponse.statusCode(200); |
| 97 | + // when |
| 98 | + HttpResponse response = getResponse(); |
| 99 | + // then |
| 100 | + assertThat(response.getStatusCode()).isEqualTo(200); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void testResponseErrorCodeForMalformedRequest() { |
| 105 | + // given |
| 106 | + testResponse.statusCode(400); |
| 107 | + // when |
| 108 | + HttpResponse response = getResponse(); |
| 109 | + // then |
| 110 | + assertThat(response.getStatusCode()).isEqualTo(400); |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + public void testResponseErrorCodeForServerError() { |
| 115 | + // given |
| 116 | + testResponse.statusCode(500); |
| 117 | + // when |
| 118 | + HttpResponse response = getResponse(); |
| 119 | + // then |
| 120 | + assertThat(response.getStatusCode()).isEqualTo(500); |
| 121 | + } |
| 122 | + |
| 123 | + @Test |
| 124 | + public void testServerErrorResponseWithConfigOptionSet() { |
| 125 | + // given |
| 126 | + testResponse.statusCode(500); |
| 127 | + try { |
| 128 | + // when |
| 129 | + connector.createRequest().configOption("throw-http-error", "TRUE").url("http://camunda.com").get().execute(); |
| 130 | + Assertions.fail("ConnectorRequestException should be thrown"); |
| 131 | + } catch (ConnectorRequestException e) { |
| 132 | + // then |
| 133 | + assertThat(e).hasMessageContaining("HTTP request failed with Status Code: 500"); |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + @Test |
| 138 | + public void testMalformedRequestWithConfigOptionSet() { |
| 139 | + // given |
| 140 | + testResponse.statusCode(400); |
| 141 | + try { |
| 142 | + // when |
| 143 | + connector.createRequest().configOption("throw-http-error", "TRUE").url("http://camunda.com").get().execute(); |
| 144 | + Assertions.fail("ConnectorRequestException should be thrown"); |
| 145 | + } catch (ConnectorRequestException e) { |
| 146 | + // then |
| 147 | + assertThat(e).hasMessageContaining("HTTP request failed with Status Code: 400"); |
| 148 | + } |
| 149 | + } |
| 150 | + |
| 151 | + @Test |
| 152 | + public void testSuccessResponseWithConfigOptionSet() { |
| 153 | + // given |
| 154 | + testResponse.statusCode(200); |
| 155 | + // when |
| 156 | + connector.createRequest().configOption("throw-http-error", "TRUE").url("http://camunda.com").get().execute(); |
| 157 | + // then |
| 158 | + HttpResponse response = getResponse(); |
| 159 | + assertThat(response.getStatusCode()).isEqualTo(200); |
| 160 | + } |
| 161 | + |
| 162 | + @Test |
| 163 | + public void testMalformedRequestWithConfigOptionSetToFalse() { |
| 164 | + // given |
| 165 | + testResponse.statusCode(400); |
| 166 | + // when |
| 167 | + connector.createRequest().configOption("throw-http-error", "FALSE").url("http://camunda.com").get().execute(); |
| 168 | + // then |
| 169 | + HttpResponse response = getResponse(); |
| 170 | + assertThat(response.getStatusCode()).isEqualTo(400); |
| 171 | + } |
| 172 | + |
91 | 173 | }
|
0 commit comments