Search in sources :

Example 1 with JSON

use of com.jayway.restassured.http.ContentType.JSON in project nakadi by zalando.

the class HilaAT method whenResetCursorsThenStreamFromResetCursorOffset.

@Test(timeout = 15000)
public void whenResetCursorsThenStreamFromResetCursorOffset() throws Exception {
    publishEvents(eventType.getName(), 20, i -> "{\"foo\":\"bar\"}");
    final TestStreamingClient client1 = TestStreamingClient.create(subscription.getId()).start();
    waitFor(() -> assertThat(client1.getBatches(), hasSize(10)));
    int statusCode = commitCursors(subscription.getId(), Collections.singletonList(client1.getBatches().get(9).getCursor()), client1.getSessionId());
    Assert.assertEquals(SC_NO_CONTENT, statusCode);
    final List<SubscriptionCursor> resetCursors = Collections.singletonList(client1.getBatches().get(4).getCursor());
    statusCode = given().body(MAPPER.writeValueAsString(new ItemsWrapper<>(resetCursors))).contentType(JSON).patch("/subscriptions/{id}/cursors", subscription.getId()).getStatusCode();
    Assert.assertEquals(SC_NO_CONTENT, statusCode);
    Assert.assertFalse(client1.isRunning());
    Assert.assertTrue(client1.getBatches().stream().anyMatch(streamBatch -> streamBatch.getMetadata() != null && streamBatch.getMetadata().getDebug().equals("Resetting subscription cursors")));
    final TestStreamingClient client2 = TestStreamingClient.create(subscription.getId()).start();
    waitFor(() -> assertThat(client2.getBatches(), hasSize(10)));
    Assert.assertEquals("001-0001-000000000000000005", client2.getBatches().get(0).getCursor().getOffset());
}
Also used : SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) CoreMatchers.is(org.hamcrest.CoreMatchers.is) NakadiTestUtils.createEventType(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createEventType) NakadiTestUtils.getNumberOfAssignedStreams(org.zalando.nakadi.webservice.utils.NakadiTestUtils.getNumberOfAssignedStreams) NakadiTestUtils.publishEvent(org.zalando.nakadi.webservice.utils.NakadiTestUtils.publishEvent) RandomSubscriptionBuilder(org.zalando.nakadi.utils.RandomSubscriptionBuilder) Matchers.not(org.hamcrest.Matchers.not) HttpStatus(org.apache.http.HttpStatus) RestAssured.given(com.jayway.restassured.RestAssured.given) Subscription(org.zalando.nakadi.domain.Subscription) BaseAT(org.zalando.nakadi.webservice.BaseAT) AUTO(org.zalando.nakadi.domain.SubscriptionEventTypeStats.Partition.AssignmentType.AUTO) StringContains(org.hamcrest.core.StringContains) StreamBatch.singleEventBatch(org.zalando.nakadi.webservice.hila.StreamBatch.singleEventBatch) SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ImmutableMap(com.google.common.collect.ImmutableMap) JSON(com.jayway.restassured.http.ContentType.JSON) BlacklistService(org.zalando.nakadi.service.BlacklistService) Collectors(java.util.stream.Collectors) NakadiTestUtils.commitCursors(org.zalando.nakadi.webservice.utils.NakadiTestUtils.commitCursors) List(java.util.List) EventTypePartitionView(org.zalando.nakadi.view.EventTypePartitionView) SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Optional(java.util.Optional) SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) SettingsControllerAT(org.zalando.nakadi.webservice.SettingsControllerAT) SC_NO_CONTENT(org.apache.http.HttpStatus.SC_NO_CONTENT) BEGIN(org.zalando.nakadi.domain.SubscriptionBase.InitialPosition.BEGIN) SubscriptionEventTypeStats(org.zalando.nakadi.domain.SubscriptionEventTypeStats) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) JsonTestHelper(org.zalando.nakadi.utils.JsonTestHelper) Cursor(org.zalando.nakadi.view.Cursor) MessageFormat.format(java.text.MessageFormat.format) Lists(com.google.common.collect.Lists) JsonConfig(org.zalando.nakadi.config.JsonConfig) ImmutableList(com.google.common.collect.ImmutableList) NakadiTestUtils(org.zalando.nakadi.webservice.utils.NakadiTestUtils) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) END(org.zalando.nakadi.domain.SubscriptionBase.InitialPosition.END) NakadiTestUtils.createSubscription(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription) Before(org.junit.Before) ItemsWrapper(org.zalando.nakadi.domain.ItemsWrapper) SESSION_ID_UNKNOWN(org.zalando.nakadi.webservice.utils.TestStreamingClient.SESSION_ID_UNKNOWN) EventType(org.zalando.nakadi.domain.EventType) Matchers.empty(org.hamcrest.Matchers.empty) RestAssured.when(com.jayway.restassured.RestAssured.when) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Matchers(org.hamcrest.Matchers) TestUtils.waitFor(org.zalando.nakadi.utils.TestUtils.waitFor) Test(org.junit.Test) IOException(java.io.IOException) DIRECT(org.zalando.nakadi.domain.SubscriptionEventTypeStats.Partition.AssignmentType.DIRECT) TimeUnit(java.util.concurrent.TimeUnit) SC_OK(org.apache.http.HttpStatus.SC_OK) MatcherIgnoringToken.equalToBatchIgnoringToken(org.zalando.nakadi.webservice.hila.StreamBatch.MatcherIgnoringToken.equalToBatchIgnoringToken) NakadiTestUtils.publishEvents(org.zalando.nakadi.webservice.utils.NakadiTestUtils.publishEvents) TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) SC_CONFLICT(org.apache.http.HttpStatus.SC_CONFLICT) Assert(org.junit.Assert) Collections(java.util.Collections) TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) ItemsWrapper(org.zalando.nakadi.domain.ItemsWrapper) Test(org.junit.Test)

Example 2 with JSON

use of com.jayway.restassured.http.ContentType.JSON in project nakadi by zalando.

the class SubscriptionAT method testSubscriptionWithManyEventTypesIsNotCreated.

@Test
public void testSubscriptionWithManyEventTypesIsNotCreated() {
    final List<String> eventTypes = IntStream.range(0, 31).mapToObj(i -> createEventType()).map(et -> et.getName()).collect(Collectors.toList());
    final String subscription = "{\"owning_application\":\"app\",\"event_types\":" + "[" + eventTypes.stream().map(et -> "\"" + et + "\"").collect(Collectors.joining(",")) + "]}";
    final Response response = given().body(subscription).contentType(JSON).post(SUBSCRIPTIONS_URL);
    // assert response
    response.then().statusCode(HttpStatus.SC_UNPROCESSABLE_ENTITY).contentType(JSON).body("title", equalTo("Unprocessable Entity")).body("detail", equalTo("total partition count for subscription is 31, but the maximum partition count is 30"));
}
Also used : PaginationLinks(org.zalando.nakadi.domain.PaginationLinks) MoreStatus(org.zalando.problem.MoreStatus) RandomSubscriptionBuilder(org.zalando.nakadi.utils.RandomSubscriptionBuilder) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Matchers.not(org.hamcrest.Matchers.not) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) HttpStatus(org.apache.http.HttpStatus) RestAssured.given(com.jayway.restassured.RestAssured.given) Stat(org.apache.zookeeper.data.Stat) Subscription(org.zalando.nakadi.domain.Subscription) BaseAT(org.zalando.nakadi.webservice.BaseAT) NakadiTestUtils.publishBusinessEventWithUserDefinedPartition(org.zalando.nakadi.webservice.utils.NakadiTestUtils.publishBusinessEventWithUserDefinedPartition) SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) Problem(org.zalando.problem.Problem) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ImmutableSet(com.google.common.collect.ImmutableSet) JSON(com.jayway.restassured.http.ContentType.JSON) TestUtils(org.zalando.nakadi.utils.TestUtils) ZookeeperTestUtils(org.zalando.nakadi.webservice.utils.ZookeeperTestUtils) Collectors(java.util.stream.Collectors) TestUtils.randomUUID(org.zalando.nakadi.utils.TestUtils.randomUUID) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) EventTypeBase(org.zalando.nakadi.domain.EventTypeBase) Optional(java.util.Optional) SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) Matchers.is(org.hamcrest.Matchers.is) NakadiTestUtils.createBusinessEventTypeWithPartitions(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createBusinessEventTypeWithPartitions) IntStream(java.util.stream.IntStream) PaginationWrapper(org.zalando.nakadi.domain.PaginationWrapper) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) SubscriptionEventTypeStats(org.zalando.nakadi.domain.SubscriptionEventTypeStats) JsonTestHelper(org.zalando.nakadi.utils.JsonTestHelper) Cursor(org.zalando.nakadi.view.Cursor) Response(com.jayway.restassured.response.Response) MessageFormat.format(java.text.MessageFormat.format) JsonConfig(org.zalando.nakadi.config.JsonConfig) ImmutableList(com.google.common.collect.ImmutableList) NakadiTestUtils(org.zalando.nakadi.webservice.utils.NakadiTestUtils) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NakadiTestUtils.createSubscription(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription) ItemsWrapper(org.zalando.nakadi.domain.ItemsWrapper) NakadiTestUtils.createSubscriptionForEventType(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscriptionForEventType) Charsets(com.google.common.base.Charsets) SESSION_ID_UNKNOWN(org.zalando.nakadi.webservice.utils.TestStreamingClient.SESSION_ID_UNKNOWN) EventType(org.zalando.nakadi.domain.EventType) RestAssured.when(com.jayway.restassured.RestAssured.when) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TestUtils.waitFor(org.zalando.nakadi.utils.TestUtils.waitFor) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) RestAssured.get(com.jayway.restassured.RestAssured.get) TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) Assert(org.junit.Assert) Response(com.jayway.restassured.response.Response) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Test(org.junit.Test)

Example 3 with JSON

use of com.jayway.restassured.http.ContentType.JSON in project nakadi by zalando.

the class SubscriptionAT method testSubscriptionWithManyEventTypesIsCreated.

@Test
public void testSubscriptionWithManyEventTypesIsCreated() throws IOException {
    final List<String> eventTypes = IntStream.range(0, 10).mapToObj(i -> createEventType()).map(EventTypeBase::getName).collect(Collectors.toList());
    final String subscription = "{\"owning_application\":\"app\",\"event_types\":" + "[" + eventTypes.stream().map(et -> "\"" + et + "\"").collect(Collectors.joining(",")) + "]}";
    final Response response = given().body(subscription).contentType(JSON).post(SUBSCRIPTIONS_URL);
    // assert response
    response.then().statusCode(HttpStatus.SC_CREATED).contentType(JSON);
    final Subscription gotSubscription = MAPPER.readValue(response.print(), Subscription.class);
    Assert.assertNotNull(gotSubscription.getId());
}
Also used : PaginationLinks(org.zalando.nakadi.domain.PaginationLinks) MoreStatus(org.zalando.problem.MoreStatus) RandomSubscriptionBuilder(org.zalando.nakadi.utils.RandomSubscriptionBuilder) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Matchers.not(org.hamcrest.Matchers.not) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) HttpStatus(org.apache.http.HttpStatus) RestAssured.given(com.jayway.restassured.RestAssured.given) Stat(org.apache.zookeeper.data.Stat) Subscription(org.zalando.nakadi.domain.Subscription) BaseAT(org.zalando.nakadi.webservice.BaseAT) NakadiTestUtils.publishBusinessEventWithUserDefinedPartition(org.zalando.nakadi.webservice.utils.NakadiTestUtils.publishBusinessEventWithUserDefinedPartition) SubscriptionCursorWithoutToken(org.zalando.nakadi.view.SubscriptionCursorWithoutToken) Problem(org.zalando.problem.Problem) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ImmutableSet(com.google.common.collect.ImmutableSet) JSON(com.jayway.restassured.http.ContentType.JSON) TestUtils(org.zalando.nakadi.utils.TestUtils) ZookeeperTestUtils(org.zalando.nakadi.webservice.utils.ZookeeperTestUtils) Collectors(java.util.stream.Collectors) TestUtils.randomUUID(org.zalando.nakadi.utils.TestUtils.randomUUID) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) EventTypeBase(org.zalando.nakadi.domain.EventTypeBase) Optional(java.util.Optional) SubscriptionCursor(org.zalando.nakadi.view.SubscriptionCursor) Matchers.is(org.hamcrest.Matchers.is) NakadiTestUtils.createBusinessEventTypeWithPartitions(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createBusinessEventTypeWithPartitions) IntStream(java.util.stream.IntStream) PaginationWrapper(org.zalando.nakadi.domain.PaginationWrapper) EventTypePartition(org.zalando.nakadi.domain.EventTypePartition) SubscriptionEventTypeStats(org.zalando.nakadi.domain.SubscriptionEventTypeStats) JsonTestHelper(org.zalando.nakadi.utils.JsonTestHelper) Cursor(org.zalando.nakadi.view.Cursor) Response(com.jayway.restassured.response.Response) MessageFormat.format(java.text.MessageFormat.format) JsonConfig(org.zalando.nakadi.config.JsonConfig) ImmutableList(com.google.common.collect.ImmutableList) NakadiTestUtils(org.zalando.nakadi.webservice.utils.NakadiTestUtils) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) NakadiTestUtils.createSubscription(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription) ItemsWrapper(org.zalando.nakadi.domain.ItemsWrapper) NakadiTestUtils.createSubscriptionForEventType(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscriptionForEventType) Charsets(com.google.common.base.Charsets) SESSION_ID_UNKNOWN(org.zalando.nakadi.webservice.utils.TestStreamingClient.SESSION_ID_UNKNOWN) EventType(org.zalando.nakadi.domain.EventType) RestAssured.when(com.jayway.restassured.RestAssured.when) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TestUtils.waitFor(org.zalando.nakadi.utils.TestUtils.waitFor) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) RestAssured.get(com.jayway.restassured.RestAssured.get) TestStreamingClient(org.zalando.nakadi.webservice.utils.TestStreamingClient) Assert(org.junit.Assert) Response(com.jayway.restassured.response.Response) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Subscription(org.zalando.nakadi.domain.Subscription) NakadiTestUtils.createSubscription(org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription) Test(org.junit.Test)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ImmutableList (com.google.common.collect.ImmutableList)3 RestAssured.given (com.jayway.restassured.RestAssured.given)3 RestAssured.when (com.jayway.restassured.RestAssured.when)3 JSON (com.jayway.restassured.http.ContentType.JSON)3 IOException (java.io.IOException)3 MessageFormat.format (java.text.MessageFormat.format)3 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 HttpStatus (org.apache.http.HttpStatus)3 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)3 Matchers.hasSize (org.hamcrest.Matchers.hasSize)3 Matchers.not (org.hamcrest.Matchers.not)3 Assert (org.junit.Assert)3 Test (org.junit.Test)3 JsonConfig (org.zalando.nakadi.config.JsonConfig)3 EventType (org.zalando.nakadi.domain.EventType)3 ItemsWrapper (org.zalando.nakadi.domain.ItemsWrapper)3