Search in sources :

Example 11 with SubscriptionBase

use of org.zalando.nakadi.domain.SubscriptionBase in project nakadi by zalando.

the class SubscriptionDbRepositoryTest method whenCreateSubscriptionThenOk.

@Test
public void whenCreateSubscriptionThenOk() throws Exception {
    final SubscriptionBase subscription = RandomSubscriptionBuilder.builder().build();
    final Subscription createdSubscription = repository.createSubscription(subscription);
    checkSubscriptionCreatedFromSubscriptionBase(createdSubscription, subscription);
    final int rows = template.queryForObject("SELECT count(*) FROM zn_data.subscription where s_id=?", Integer.class, createdSubscription.getId());
    assertThat("Number of rows should be 1", rows, equalTo(1));
    final Map<String, Object> result = template.queryForMap("SELECT s_subscription_object FROM zn_data.subscription WHERE s_id=?", createdSubscription.getId());
    final ObjectMapper mapper = (new JsonConfig()).jacksonObjectMapper();
    final Subscription saved = mapper.readValue(result.get("s_subscription_object").toString(), Subscription.class);
    assertThat("Saved subscription equal to original one", saved, equalTo(createdSubscription));
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) JsonConfig(org.zalando.nakadi.config.JsonConfig) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Subscription(org.zalando.nakadi.domain.Subscription) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 12 with SubscriptionBase

use of org.zalando.nakadi.domain.SubscriptionBase in project nakadi by zalando.

the class HilaAT method before.

@Before
public void before() throws IOException {
    // create event-type and subscribe to it
    eventType = createEventType();
    final SubscriptionBase subscription = RandomSubscriptionBuilder.builder().withEventType(eventType.getName()).withStartFrom(BEGIN).buildSubscriptionBase();
    this.subscription = createSubscription(subscription);
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Before(org.junit.Before)

Example 13 with SubscriptionBase

use of org.zalando.nakadi.domain.SubscriptionBase in project nakadi by zalando.

the class SubscriptionDbRepositoryTest method whenCreateSubscriptionWithDuplicatedKeyParamsThenDuplicatedSubscriptionException.

@Test(expected = DuplicatedSubscriptionException.class)
public void whenCreateSubscriptionWithDuplicatedKeyParamsThenDuplicatedSubscriptionException() throws Exception {
    final SubscriptionBase subscription = RandomSubscriptionBuilder.builder().build();
    repository.createSubscription(subscription);
    // try to create subscription second time
    repository.createSubscription(subscription);
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Test(org.junit.Test)

Example 14 with SubscriptionBase

use of org.zalando.nakadi.domain.SubscriptionBase in project nakadi by zalando.

the class PostSubscriptionControllerTest method whenEventTypeDoesNotExistThenUnprocessableEntity.

@Test
public void whenEventTypeDoesNotExistThenUnprocessableEntity() throws Exception {
    final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase();
    when(subscriptionService.getExistingSubscription(any())).thenThrow(new NoSubscriptionException("", null));
    when(subscriptionService.createSubscription(any())).thenThrow(new NoEventTypeException("msg"));
    final Problem expectedProblem = Problem.valueOf(UNPROCESSABLE_ENTITY, "msg");
    checkForProblem(postSubscription(subscriptionBase), expectedProblem);
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) NoSubscriptionException(org.zalando.nakadi.exceptions.runtime.NoSubscriptionException) Problem(org.zalando.problem.Problem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) NoEventTypeException(org.zalando.nakadi.exceptions.runtime.NoEventTypeException) Test(org.junit.Test)

Example 15 with SubscriptionBase

use of org.zalando.nakadi.domain.SubscriptionBase in project nakadi by zalando.

the class PostSubscriptionControllerTest method whenPostValidSubscriptionThenOk.

@Test
public void whenPostValidSubscriptionThenOk() throws Exception {
    final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase();
    final Subscription subscription = new Subscription("123", new DateTime(DateTimeZone.UTC), subscriptionBase);
    when(subscriptionService.getExistingSubscription(any())).thenThrow(new NoSubscriptionException("", null));
    when(subscriptionService.createSubscription(any())).thenReturn(subscription);
    postSubscription(subscriptionBase).andExpect(status().isCreated()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(content().string(sameJSONAs(TestUtils.JSON_TEST_HELPER.asJsonString(subscription)))).andExpect(header().string("Location", "/subscriptions/123")).andExpect(header().string("Content-Location", "/subscriptions/123"));
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) NoSubscriptionException(org.zalando.nakadi.exceptions.runtime.NoSubscriptionException) Subscription(org.zalando.nakadi.domain.Subscription) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

SubscriptionBase (org.zalando.nakadi.domain.SubscriptionBase)24 Test (org.junit.Test)19 Subscription (org.zalando.nakadi.domain.Subscription)7 TestUtils.invalidProblem (org.zalando.nakadi.utils.TestUtils.invalidProblem)6 Problem (org.zalando.problem.Problem)6 Before (org.junit.Before)4 EventType (org.zalando.nakadi.domain.EventType)4 NoSubscriptionException (org.zalando.nakadi.exceptions.runtime.NoSubscriptionException)4 DateTime (org.joda.time.DateTime)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 JsonConfig (org.zalando.nakadi.config.JsonConfig)2 NoEventTypeException (org.zalando.nakadi.exceptions.runtime.NoEventTypeException)2 SubscriptionCursorWithoutToken (org.zalando.nakadi.view.SubscriptionCursorWithoutToken)2 NakadiTestUtils.createSubscription (org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription)2 TestStreamingClient (org.zalando.nakadi.webservice.utils.TestStreamingClient)2 Charsets (com.google.common.base.Charsets)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Resources (com.google.common.io.Resources)1 RestAssured (com.jayway.restassured.RestAssured)1