Search in sources :

Example 66 with EventType

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

the class MetadataEnrichmentStrategyTest method setEventTypeSchemaVersion.

@Test
public void setEventTypeSchemaVersion() throws Exception {
    final EventType eventType = buildDefaultEventType();
    final JSONObject event = buildBusinessEvent();
    final BatchItem batchItem = createBatchItem(event);
    assertThat(batchItem.getEvent().getJSONObject("metadata").optString("version"), isEmptyString());
    strategy.enrich(batchItem, eventType);
    assertThat(batchItem.getEvent().getJSONObject("metadata").getString("version"), equalTo("1.0.0"));
}
Also used : JSONObject(org.json.JSONObject) EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) TestUtils.createBatchItem(org.zalando.nakadi.utils.TestUtils.createBatchItem) BatchItem(org.zalando.nakadi.domain.BatchItem) Test(org.junit.Test)

Example 67 with EventType

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

the class SchemaControllerTest method testGetLatestSchemaVersionThen200.

@Test
public void testGetLatestSchemaVersionThen200() {
    final EventType eventType = buildDefaultEventType();
    Mockito.when(eventTypeService.get(eventType.getName())).thenReturn(Result.ok(eventType));
    final ResponseEntity<?> result = new SchemaController(schemaService, eventTypeService).getSchemaVersion(eventType.getName(), "latest", nativeWebRequest);
    Assert.assertEquals(HttpStatus.OK, result.getStatusCode());
    Assert.assertEquals(eventType.getSchema().toString(), result.getBody().toString());
}
Also used : EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Test(org.junit.Test)

Example 68 with EventType

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

the class SchemaControllerTest method testGetLatestSchemaVersionByNumberThen200.

@Test
public void testGetLatestSchemaVersionByNumberThen200() {
    final EventType eventType = buildDefaultEventType();
    Mockito.when(schemaService.getSchemaVersion(eventType.getName(), eventType.getSchema().getVersion().toString())).thenReturn(Result.ok(eventType.getSchema()));
    final ResponseEntity<?> result = new SchemaController(schemaService, eventTypeService).getSchemaVersion(eventType.getName(), eventType.getSchema().getVersion().toString(), nativeWebRequest);
    Assert.assertEquals(HttpStatus.OK, result.getStatusCode());
    Assert.assertEquals(eventType.getSchema().toString(), result.getBody().toString());
}
Also used : EventType(org.zalando.nakadi.domain.EventType) TestUtils.buildDefaultEventType(org.zalando.nakadi.utils.TestUtils.buildDefaultEventType) Test(org.junit.Test)

Example 69 with EventType

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

the class EventTypeAuthorizationTest method whenDELETENotAuthorized200.

@Test
public void whenDELETENotAuthorized200() throws Exception {
    final EventType eventType = EventTypeTestBuilder.builder().build();
    final Resource resource = new EventTypeResource(eventType.getName(), eventType.getAuthorization());
    doReturn(Optional.of(eventType)).when(eventTypeRepository).findByNameO(any());
    doThrow(new AccessDeniedException(AuthorizationService.Operation.ADMIN, resource)).when(authorizationValidator).authorizeEventTypeAdmin(eventType);
    deleteEventType(eventType.getName()).andExpect(status().isForbidden()).andExpect(content().string(matchesProblem(Problem.valueOf(Response.Status.FORBIDDEN, "Access on ADMIN event-type:" + eventType.getName() + " denied"))));
}
Also used : AccessDeniedException(org.zalando.nakadi.exceptions.runtime.AccessDeniedException) EventType(org.zalando.nakadi.domain.EventType) Resource(org.zalando.nakadi.plugin.api.authz.Resource) EventTypeResource(org.zalando.nakadi.domain.EventTypeResource) EventTypeResource(org.zalando.nakadi.domain.EventTypeResource) Test(org.junit.Test)

Example 70 with EventType

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

the class SchemaEvolutionService method bumpVersion.

private EventType bumpVersion(final EventType original, final EventTypeBase eventType, final Version.Level changeLevel) {
    final DateTime now = new DateTime(DateTimeZone.UTC);
    final String newVersion = original.getSchema().getVersion().bump(changeLevel).toString();
    return new EventType(eventType, newVersion, original.getCreatedAt(), now);
}
Also used : EventType(org.zalando.nakadi.domain.EventType) DateTime(org.joda.time.DateTime)

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