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));
}
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);
}
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);
}
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);
}
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"));
}
Aggregations