Search in sources :

Example 46 with EventType

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

the class SchemaServiceTest method testIllegalVersionNumber.

@Test
public void testIllegalVersionNumber() throws Exception {
    final EventType eventType = buildDefaultEventType();
    Mockito.when(schemaRepository.getSchemaVersion(eventType.getName() + "wrong", eventType.getSchema().getVersion().toString())).thenThrow(NoSuchSchemaException.class);
    final Result<EventTypeSchema> result = schemaService.getSchemaVersion(eventType.getName() + "wrong", eventType.getSchema().getVersion().toString());
    Assert.assertFalse(result.isSuccessful());
    Assert.assertEquals(Response.Status.NOT_FOUND, result.getProblem().getStatus());
}
Also used : EventTypeSchema(org.zalando.nakadi.domain.EventTypeSchema) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Test(org.junit.Test)

Example 47 with EventType

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

the class TimelineServiceTest method testGetTimeline.

@Test
public void testGetTimeline() throws Exception {
    final EventType eventType = EventTypeTestBuilder.builder().build();
    final Timeline timeline = Timeline.createTimeline(eventType.getName(), 0, null, "topic", new Date());
    timeline.setSwitchedAt(new Date());
    Mockito.when(eventTypeCache.getTimelinesOrdered(eventType.getName())).thenReturn(Collections.singletonList(timeline));
    final Timeline actualTimeline = timelineService.getActiveTimeline(eventType);
    Assert.assertEquals(timeline, actualTimeline);
}
Also used : Timeline(org.zalando.nakadi.domain.Timeline) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) EventType(org.zalando.nakadi.domain.EventType) Date(java.util.Date) Test(org.junit.Test)

Example 48 with EventType

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

the class JSONSchemaValidationTest method validationOfBusinessEventShouldRequiredMetadata.

@Test
public void validationOfBusinessEventShouldRequiredMetadata() {
    final EventType et = EventTypeTestBuilder.builder().name("some-event-type").schema(basicSchema()).build();
    et.setCategory(EventCategory.BUSINESS);
    final JSONObject event = new JSONObject("{ \"foo\": \"bar\" }");
    final Optional<ValidationError> error = EventValidation.forType(et).validate(event);
    assertThat(error.get().getMessage(), equalTo("#: required key [metadata] not found"));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 49 with EventType

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

the class JSONSchemaValidationTest method requireMetadataEventTypeToBeTheSameAsEventTypeName.

@Test
public void requireMetadataEventTypeToBeTheSameAsEventTypeName() {
    final EventType et = EventTypeTestBuilder.builder().name("some-event-type").schema(basicSchema()).build();
    et.setCategory(EventCategory.BUSINESS);
    final JSONObject event = businessEvent();
    event.getJSONObject("metadata").put("event_type", "different-from-event-name");
    final Optional<ValidationError> error = EventValidation.forType(et).validate(event);
    assertThat(error.get().getMessage(), equalTo("#/metadata/event_type: different-from-event-name " + "is not a valid enum value"));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Example 50 with EventType

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

the class JSONSchemaValidationTest method requireEidToBeFormattedAsUUID.

@Test
public void requireEidToBeFormattedAsUUID() {
    final EventType et = EventTypeTestBuilder.builder().name("some-event-type").schema(basicSchema()).build();
    et.setCategory(EventCategory.BUSINESS);
    final JSONObject event = businessEvent();
    event.getJSONObject("metadata").put("eid", "x");
    final Optional<ValidationError> error = EventValidation.forType(et).validate(event);
    assertThat(error.get().getMessage(), equalTo("#/metadata/eid: string [x] does not match pattern " + "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$"));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) Test(org.junit.Test)

Aggregations

EventType (org.zalando.nakadi.domain.EventType)216 Test (org.junit.Test)183 TestUtils.buildDefaultEventType (org.zalando.nakadi.utils.TestUtils.buildDefaultEventType)138 JSONObject (org.json.JSONObject)40 Problem (org.zalando.problem.Problem)21 InternalNakadiException (org.zalando.nakadi.exceptions.InternalNakadiException)18 Matchers.containsString (org.hamcrest.Matchers.containsString)17 JSONArray (org.json.JSONArray)17 EventPublishResult (org.zalando.nakadi.domain.EventPublishResult)17 TestUtils.invalidProblem (org.zalando.nakadi.utils.TestUtils.invalidProblem)17 ThrowableProblem (org.zalando.problem.ThrowableProblem)17 Timeline (org.zalando.nakadi.domain.Timeline)16 NoSuchEventTypeException (org.zalando.nakadi.exceptions.NoSuchEventTypeException)14 EventTypeTestBuilder (org.zalando.nakadi.utils.EventTypeTestBuilder)14 BatchItem (org.zalando.nakadi.domain.BatchItem)12 TestUtils.resourceAsString (org.zalando.nakadi.utils.TestUtils.resourceAsString)12 List (java.util.List)11 Subscription (org.zalando.nakadi.domain.Subscription)11 TestUtils.createBatchItem (org.zalando.nakadi.utils.TestUtils.createBatchItem)11 Collectors (java.util.stream.Collectors)9