Skip to content

Commit 548e9c8

Browse files
author
Stephen Powis
committed
add missing test cases
1 parent 529b275 commit 548e9c8

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

src/test/java/org/sourcelab/kafka/connect/apiclient/KafkaConnectClientUnitTest.java

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.junit.Test;
2222
import org.sourcelab.kafka.connect.apiclient.rest.RestClient;
2323
import org.sourcelab.kafka.connect.apiclient.rest.RestResponse;
24+
import org.sourcelab.kafka.connect.apiclient.rest.exceptions.ConcurrentConfigModificationException;
25+
import org.sourcelab.kafka.connect.apiclient.rest.exceptions.ResourceNotFoundException;
2426
import org.sourcelab.kafka.connect.apiclient.rest.exceptions.UnauthorizedRequestException;
2527

2628
import static org.mockito.ArgumentMatchers.any;
@@ -32,15 +34,14 @@
3234
*/
3335
public class KafkaConnectClientUnitTest {
3436

37+
private final Configuration configuration = new Configuration("http://localhost:9092");
38+
3539
/**
3640
* This test verifies that if the underlying RestClient returns a response with Http Status Code 401,
3741
* then KafkaConnectClient will throw an UnauthorizedRequestException.
3842
*/
3943
@Test(expected = UnauthorizedRequestException.class)
4044
public void unAuthorizedException() {
41-
// Create configuration
42-
final Configuration configuration = new Configuration("http://localhost:9092");
43-
4445
// Create mock RestResponse
4546
final RestResponse restResponse = new RestResponse("Invalid credentials.", HttpStatus.SC_UNAUTHORIZED);
4647

@@ -55,4 +56,52 @@ public void unAuthorizedException() {
5556
// Call any method that makes a request via RestClient.
5657
client.getConnectors();
5758
}
58-
}
59+
60+
/**
61+
* This test verifies that if the underlying RestClient returns a response with Http Status Code 404,
62+
* then KafkaConnectClient will throw a ResourceNotFoundException.
63+
*/
64+
@Test(expected = ResourceNotFoundException.class)
65+
public void on404_resourceNotFoundException() {
66+
// Create mock RestResponse
67+
final String connectorName = "DoesNotExist";
68+
final String result = "{\"error_code\":404,\"message\":\"Connector " + connectorName + " not found\"}";
69+
70+
final RestResponse restResponse = new RestResponse(result, HttpStatus.SC_NOT_FOUND);
71+
72+
// Create mock RestClient
73+
final RestClient mockRestClient = mock(RestClient.class);
74+
when(mockRestClient.submitRequest(any()))
75+
.thenReturn(restResponse);
76+
77+
// Create client
78+
final KafkaConnectClient client = new KafkaConnectClient(configuration, mockRestClient);
79+
80+
// Call any method that makes a request via RestClient.
81+
client.getConnector(connectorName);
82+
}
83+
84+
/**
85+
* This test verifies that if the underlying RestClient returns a response with Http Status Code 409,
86+
* then KafkaConnectClient will throw a ConcurrentConfigModificationException.
87+
*/
88+
@Test(expected = ConcurrentConfigModificationException.class)
89+
public void on409_concurrentConfigModificationException() {
90+
// Create mock RestResponse
91+
final String connectorName = "DoesNotExist";
92+
final String result = "{\"error_code\":409,\"message\":\"Rebalance in progress.\"}";
93+
94+
final RestResponse restResponse = new RestResponse(result, HttpStatus.SC_CONFLICT);
95+
96+
// Create mock RestClient
97+
final RestClient mockRestClient = mock(RestClient.class);
98+
when(mockRestClient.submitRequest(any()))
99+
.thenReturn(restResponse);
100+
101+
// Create client
102+
final KafkaConnectClient client = new KafkaConnectClient(configuration, mockRestClient);
103+
104+
// Call any method that makes a request via RestClient.
105+
client.getConnector(connectorName);
106+
}
107+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"error_code":404,"message":"Connector DoesNotExist not found"}

0 commit comments

Comments
 (0)