use of javax.ws.rs.core.HttpHeaders in project kafka by apache.
the class ConnectorsResourceTest method testResetConnectorActiveTopicsWithTopicTrackingDisabled.
@Test
public void testResetConnectorActiveTopicsWithTopicTrackingDisabled() {
PowerMock.reset(workerConfig);
EasyMock.expect(workerConfig.getBoolean(TOPIC_TRACKING_ENABLE_CONFIG)).andReturn(false);
EasyMock.expect(workerConfig.getBoolean(TOPIC_TRACKING_ALLOW_RESET_CONFIG)).andReturn(true);
HttpHeaders headers = EasyMock.mock(HttpHeaders.class);
PowerMock.replay(workerConfig);
connectorsResource = new ConnectorsResource(herder, workerConfig);
PowerMock.replayAll();
Exception e = assertThrows(ConnectRestException.class, () -> connectorsResource.resetConnectorActiveTopics(CONNECTOR_NAME, headers));
assertEquals("Topic tracking is disabled.", e.getMessage());
PowerMock.verifyAll();
}
use of javax.ws.rs.core.HttpHeaders in project kafka by apache.
the class ConnectorsResourceTest method testResetConnectorActiveTopics.
@Test
public void testResetConnectorActiveTopics() {
PowerMock.reset(workerConfig);
EasyMock.expect(workerConfig.getBoolean(TOPIC_TRACKING_ENABLE_CONFIG)).andReturn(true);
EasyMock.expect(workerConfig.getBoolean(TOPIC_TRACKING_ALLOW_RESET_CONFIG)).andReturn(true);
HttpHeaders headers = EasyMock.mock(HttpHeaders.class);
herder.resetConnectorActiveTopics(CONNECTOR_NAME);
EasyMock.expectLastCall();
PowerMock.replay(workerConfig);
connectorsResource = new ConnectorsResource(herder, workerConfig);
PowerMock.replayAll();
Response response = connectorsResource.resetConnectorActiveTopics(CONNECTOR_NAME, headers);
assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
PowerMock.verifyAll();
}
use of javax.ws.rs.core.HttpHeaders in project kafka by apache.
the class ConnectorsResourceTest method testCreateConnectorWithHeaderAuthorization.
@Test
public void testCreateConnectorWithHeaderAuthorization() throws Throwable {
CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));
final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
HttpHeaders httpHeaders = EasyMock.mock(HttpHeaders.class);
EasyMock.expect(httpHeaders.getHeaderString("Authorization")).andReturn("Basic YWxhZGRpbjpvcGVuc2VzYW1l").times(1);
EasyMock.replay(httpHeaders);
herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES, ConnectorType.SOURCE)));
PowerMock.replayAll();
connectorsResource.createConnector(FORWARD, httpHeaders, body);
PowerMock.verifyAll();
}
use of javax.ws.rs.core.HttpHeaders in project kafka by apache.
the class ConnectorsResourceTest method testCreateConnectorWithoutHeaderAuthorization.
@Test
public void testCreateConnectorWithoutHeaderAuthorization() throws Throwable {
CreateConnectorRequest body = new CreateConnectorRequest(CONNECTOR_NAME, Collections.singletonMap(ConnectorConfig.NAME_CONFIG, CONNECTOR_NAME));
final Capture<Callback<Herder.Created<ConnectorInfo>>> cb = Capture.newInstance();
HttpHeaders httpHeaders = EasyMock.mock(HttpHeaders.class);
EasyMock.expect(httpHeaders.getHeaderString("Authorization")).andReturn(null).times(1);
EasyMock.replay(httpHeaders);
herder.putConnectorConfig(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(body.config()), EasyMock.eq(false), EasyMock.capture(cb));
expectAndCallbackResult(cb, new Herder.Created<>(true, new ConnectorInfo(CONNECTOR_NAME, CONNECTOR_CONFIG, CONNECTOR_TASK_NAMES, ConnectorType.SOURCE)));
PowerMock.replayAll();
connectorsResource.createConnector(FORWARD, httpHeaders, body);
PowerMock.verifyAll();
}
use of javax.ws.rs.core.HttpHeaders in project kafka by apache.
the class ConnectorsResourceTest method testPutConnectorTaskConfigsWithInternalRequestSignature.
@Test
public void testPutConnectorTaskConfigsWithInternalRequestSignature() throws Throwable {
final String signatureAlgorithm = "HmacSHA256";
final String encodedSignature = "Kv1/OSsxzdVIwvZ4e30avyRIVrngDfhzVUm/kAZEKc4=";
final Capture<Callback<Void>> cb = Capture.newInstance();
final Capture<InternalRequestSignature> signatureCapture = Capture.newInstance();
herder.putTaskConfigs(EasyMock.eq(CONNECTOR_NAME), EasyMock.eq(TASK_CONFIGS), EasyMock.capture(cb), EasyMock.capture(signatureCapture));
expectAndCallbackResult(cb, null);
HttpHeaders headers = EasyMock.mock(HttpHeaders.class);
EasyMock.expect(headers.getHeaderString(InternalRequestSignature.SIGNATURE_ALGORITHM_HEADER)).andReturn(signatureAlgorithm).once();
EasyMock.expect(headers.getHeaderString(InternalRequestSignature.SIGNATURE_HEADER)).andReturn(encodedSignature).once();
PowerMock.replayAll(headers);
connectorsResource.putTaskConfigs(CONNECTOR_NAME, headers, FORWARD, serializeAsBytes(TASK_CONFIGS));
PowerMock.verifyAll();
InternalRequestSignature expectedSignature = new InternalRequestSignature(serializeAsBytes(TASK_CONFIGS), Mac.getInstance(signatureAlgorithm), Base64.getDecoder().decode(encodedSignature));
assertEquals(expectedSignature, signatureCapture.getValue());
}
Aggregations