Search in sources :

Example 41 with HttpHeaders

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();
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) RebalanceNeededException(org.apache.kafka.connect.runtime.distributed.RebalanceNeededException) AlreadyExistsException(org.apache.kafka.connect.errors.AlreadyExistsException) NotLeaderException(org.apache.kafka.connect.runtime.distributed.NotLeaderException) BadRequestException(javax.ws.rs.BadRequestException) NotFoundException(org.apache.kafka.connect.errors.NotFoundException) NotAssignedException(org.apache.kafka.connect.runtime.distributed.NotAssignedException) ConnectRestException(org.apache.kafka.connect.runtime.rest.errors.ConnectRestException) IOException(java.io.IOException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 42 with HttpHeaders

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();
}
Also used : Response(javax.ws.rs.core.Response) HttpHeaders(javax.ws.rs.core.HttpHeaders) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 43 with HttpHeaders

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();
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) CreateConnectorRequest(org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 44 with HttpHeaders

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();
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) Callback(org.apache.kafka.connect.util.Callback) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) CreateConnectorRequest(org.apache.kafka.connect.runtime.rest.entities.CreateConnectorRequest) Herder(org.apache.kafka.connect.runtime.Herder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 45 with HttpHeaders

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());
}
Also used : InternalRequestSignature(org.apache.kafka.connect.runtime.rest.InternalRequestSignature) HttpHeaders(javax.ws.rs.core.HttpHeaders) Callback(org.apache.kafka.connect.util.Callback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

HttpHeaders (javax.ws.rs.core.HttpHeaders)95 Test (org.junit.Test)57 Message (org.apache.cxf.message.Message)31 Optional (java.util.Optional)13 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 UriInfo (javax.ws.rs.core.UriInfo)12 CatalogFramework (ddf.catalog.CatalogFramework)10 Locale (java.util.Locale)10 Response (javax.ws.rs.core.Response)10 MultipartBody (org.apache.cxf.jaxrs.ext.multipart.MultipartBody)10 JsonObject (com.google.gson.JsonObject)9 MediaType (javax.ws.rs.core.MediaType)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Map (java.util.Map)8 Cookie (javax.ws.rs.core.Cookie)8 IOException (java.io.IOException)7 Collections (java.util.Collections)7 WebApplicationException (javax.ws.rs.WebApplicationException)7 URI (java.net.URI)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6