Skip to content

Commit c35b144

Browse files
author
Stephen Powis
committed
Add additional test case
1 parent e6f89e2 commit c35b144

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
44

55
## 1.2.0 (UNRELEASED)
66

7+
### New Features
8+
- Added ability to authenticate with Kafka-Connect REST endpoints utilizing Basic-Authentication.
79

810
## 1.1.0 (01/30/2019)
911

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@
129129
<scope>test</scope>
130130
</dependency>
131131

132+
<!-- Mocking in Tests -->
133+
<dependency>
134+
<groupId>org.mockito</groupId>
135+
<artifactId>mockito-core</artifactId>
136+
<version>2.23.4</version>
137+
<scope>test</scope>
138+
</dependency>
139+
140+
132141
<!-- Data providers on tests -->
133142
<dependency>
134143
<groupId>com.tngtech.java</groupId>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Copyright 2018, 2019 SourceLab.org https://github.com/SourceLabOrg/kafka-connect-client
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7+
* persons to whom the Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10+
* Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13+
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16+
*/
17+
18+
package org.sourcelab.kafka.connect.apiclient;
19+
20+
import org.apache.http.HttpStatus;
21+
import org.junit.Test;
22+
import org.sourcelab.kafka.connect.apiclient.rest.RestClient;
23+
import org.sourcelab.kafka.connect.apiclient.rest.RestResponse;
24+
import org.sourcelab.kafka.connect.apiclient.rest.exceptions.UnauthorizedRequestException;
25+
26+
import static org.mockito.ArgumentMatchers.any;
27+
import static org.mockito.Mockito.mock;
28+
import static org.mockito.Mockito.when;
29+
30+
/**
31+
* Unit tests over KafkaConnectClient.
32+
*/
33+
public class KafkaConnectClientUnitTest {
34+
35+
/**
36+
* This test verifies that if the underlying RestClient returns a response with Http Status Code 401,
37+
* then KafkaConnectClient will throw an UnauthorizedRequestException.
38+
*/
39+
@Test(expected = UnauthorizedRequestException.class)
40+
public void unAuthorizedException() {
41+
// Create configuration
42+
final Configuration configuration = new Configuration("http://localhost:9092");
43+
44+
// Create mock RestResponse
45+
final RestResponse restResponse = new RestResponse("Invalid credentials.", HttpStatus.SC_UNAUTHORIZED);
46+
47+
// Create mock RestClient
48+
final RestClient mockRestClient = mock(RestClient.class);
49+
when(mockRestClient.submitRequest(any()))
50+
.thenReturn(restResponse);
51+
52+
// Create client
53+
final KafkaConnectClient client = new KafkaConnectClient(configuration, mockRestClient);
54+
55+
// Call any method that makes a request via RestClient.
56+
client.getConnectors();
57+
}
58+
}

0 commit comments

Comments
 (0)