Search in sources :

Example 1 with SubscriptionBase

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

the class PostSubscriptionControllerTest method whenSubscriptionCreationIsDisabledThenCreationFails.

@Test
public void whenSubscriptionCreationIsDisabledThenCreationFails() throws Exception {
    final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase();
    when(subscriptionService.getExistingSubscription(any())).thenThrow(new NoSubscriptionException("", null));
    when(featureToggleService.isFeatureEnabled(DISABLE_SUBSCRIPTION_CREATION)).thenReturn(true);
    postSubscription(subscriptionBase).andExpect(status().isServiceUnavailable());
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) NoSubscriptionException(org.zalando.nakadi.exceptions.runtime.NoSubscriptionException) Test(org.junit.Test)

Example 2 with SubscriptionBase

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

the class PostSubscriptionControllerTest method whenMoreThanAllowedEventTypeThenUnprocessableEntity.

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

Example 3 with SubscriptionBase

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

the class PostSubscriptionControllerTest method whenCreateSubscriptionWithUnknownApplicationThenUnprocessableEntity.

@Test
public void whenCreateSubscriptionWithUnknownApplicationThenUnprocessableEntity() throws Exception {
    final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase();
    when(applicationService.exists(any())).thenReturn(false);
    postSubscription(subscriptionBase).andExpect(status().isUnprocessableEntity()).andExpect(content().contentTypeCompatibleWith("application/problem+json"));
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Test(org.junit.Test)

Example 4 with SubscriptionBase

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

the class PostSubscriptionControllerTest method whenEventTypesIsEmptyThenUnprocessableEntity.

@Test
public void whenEventTypesIsEmptyThenUnprocessableEntity() throws Exception {
    final SubscriptionBase subscriptionBase = builder().withEventTypes(ImmutableSet.of()).buildSubscriptionBase();
    final Problem expectedProblem = invalidProblem("event_types", "must contain at least one element");
    checkForProblem(postSubscription(subscriptionBase), expectedProblem);
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) Problem(org.zalando.problem.Problem) TestUtils.invalidProblem(org.zalando.nakadi.utils.TestUtils.invalidProblem) Test(org.junit.Test)

Example 5 with SubscriptionBase

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

the class PostSubscriptionControllerTest method whenSubscriptionCreationDisabledThenReturnExistentSubscription.

@Test
public void whenSubscriptionCreationDisabledThenReturnExistentSubscription() throws Exception {
    final SubscriptionBase subscriptionBase = builder().buildSubscriptionBase();
    final Subscription existingSubscription = new Subscription("123", new DateTime(DateTimeZone.UTC), subscriptionBase);
    existingSubscription.setReadFrom(SubscriptionBase.InitialPosition.BEGIN);
    when(subscriptionService.getExistingSubscription(any())).thenReturn(existingSubscription);
    when(featureToggleService.isFeatureEnabled(DISABLE_SUBSCRIPTION_CREATION)).thenReturn(true);
    postSubscription(subscriptionBase).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(content().string(sameJSONAs(TestUtils.JSON_TEST_HELPER.asJsonString(existingSubscription)))).andExpect(header().string("Location", "/subscriptions/123")).andExpect(header().doesNotExist("Content-Location"));
}
Also used : SubscriptionBase(org.zalando.nakadi.domain.SubscriptionBase) 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