Skip to content

Commit b021eac

Browse files
authored
KREST-10790 Handle TopicDeletionDisabledException as 400 (#1176)
1 parent de196ae commit b021eac

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2023 Confluent Inc.
3+
*
4+
* Licensed under the Confluent Community License (the "License"); you may not use
5+
* this file except in compliance with the License. You may obtain a copy of the
6+
* License at
7+
*
8+
* http://www.confluent.io/confluent-community-license
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
13+
* specific language governing permissions and limitations under the License.
14+
*/
15+
16+
package io.confluent.kafkarest.exceptions;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
21+
import io.confluent.rest.entities.ErrorMessage;
22+
import javax.ws.rs.core.Response;
23+
import javax.ws.rs.core.Response.Status;
24+
import org.apache.kafka.common.errors.SerializationException;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
28+
public class KafkaRestExceptionMapperTest {
29+
30+
private KafkaRestExceptionMapper exceptionMapper;
31+
32+
@BeforeEach
33+
public void setUp() {
34+
exceptionMapper = new KafkaRestExceptionMapper(null);
35+
}
36+
37+
@Test
38+
public void test_whenSerializationExceptionThrown_thenCorrectResponseStatusIsSet() {
39+
verifyMapperResponse(
40+
new SerializationException("some message"), Status.REQUEST_TIMEOUT, 40801, "some message");
41+
}
42+
43+
private void verifyMapperResponse(
44+
Throwable throwable, Status status, int errorCode, String exceptionMessage) {
45+
Response response = exceptionMapper.toResponse(throwable);
46+
assertNotNull(response);
47+
assertEquals(status.getStatusCode(), response.getStatus());
48+
ErrorMessage errorMessage = (ErrorMessage) response.getEntity();
49+
assertEquals(errorCode, errorMessage.getErrorCode());
50+
assertEquals(exceptionMessage, throwable.getMessage());
51+
}
52+
}

0 commit comments

Comments
 (0)