<commit_before>package org.zalando.nakadi.webservice;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Header;
import com.jayway.restassured.specification.RequestSpecification;
import org.echocat.jomon.runtime.concurrent.RetryForSpecifiedTimeStrategy;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.zalando.nakadi.config.JsonConfig;
import org.zalando.nakadi.domain.EventType;
import org.zalando.nakadi.domain.StreamMetadata;
import org.zalando.nakadi.domain.Subscription;
import org.zalando.nakadi.domain.SubscriptionBase;
import org.zalando.nakadi.domain.SubscriptionCursor;
import org.zalando.nakadi.utils.RandomSubscriptionBuilder;
import org.zalando.nakadi.webservice.hila.StreamBatch;
import org.zalando.nakadi.webservice.utils.TestStreamingClient;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.http.ContentType.JSON;
import static java.util.stream.IntStream.rangeClosed;
import static org.echocat.jomon.runtime.concurrent.Retryer.executeWithRetry;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK;
import static org.zalando.nakadi.domain.SubscriptionBase.InitialPosition.BEGIN;
import static org.zalando.nakadi.utils.TestUtils.randomTextString;
import static org.zalando.nakadi.utils.TestUtils.randomValidEventTypeName;
import static org.zalando.nakadi.utils.TestUtils.waitFor;
import static org.zalando.nakadi.webservice.hila.StreamBatch.MatcherIgnoringToken.equalToBatchIgnoringToken;
import static org.zalando.nakadi.webservice.utils.NakadiTestUtils.commitCursors;
import static org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription;

public class UserJourneyAT extends RealEnvironmentAT {

    private static final String EVENT1 = "{\"foo\":\"" + randomTextString() + "\"}";
    private static final String EVENT2 = "{\"foo\":\"" + randomTextString() + "\"}";

    private static final ObjectMapper MAPPER = (new JsonConfig()).jacksonObjectMapper();
    private static final String ENDPOINT = "/event-types";

    private String eventTypeName;

    private String eventTypeBody;
    private String eventTypeBodyUpdate;

    @Before
    public void before() throws IOException {
        eventTypeName = randomValidEventTypeName();
        eventTypeBody = getEventTypeJsonFromFile("sample-event-type.json", eventTypeName, owningApp);
        eventTypeBodyUpdate = getEventTypeJsonFromFile("sample-event-type-update.json", eventTypeName, owningApp);
    }

    @SuppressWarnings("unchecked")
    @Test(timeout = 15000)
    public void userJourneyM1() throws InterruptedException, IOException {
        // create event-type
        createEventType();

        // get event type
        jsonRequestSpec()
                .when()
                .get("/event-types/" + eventTypeName)
                .then()
                .statusCode(OK.value())
                .body("name", equalTo(eventTypeName))
                .body("owning_application", equalTo(owningApp))
                .body("category", equalTo("undefined"))
                .body("schema.type", equalTo("json_schema"))
                .body("schema.schema", equalTo("{\"type\": \"object\", \"properties\": " +
                        "{\"foo\": {\"type\": \"string\"}}, \"required\": [\"foo\"]}"));

        // list event types
        jsonRequestSpec()
                .when()
                .get("/event-types")
                .then()
                .statusCode(OK.value())
                .body("size()", Matchers.greaterThan(0))
                .body("name[0]", notNullValue())
                .body("owning_application[0]", notNullValue())
                .body("category[0]", notNullValue())
                .body("schema.type[0]", notNullValue())
                .body("schema.schema[0]", notNullValue());

        final String updateEvetyTypeBody = getUpdateEventType();

        // update event-type
        jsonRequestSpec()
                .body(updateEvetyTypeBody)
                .when()
                .put("/event-types/" + eventTypeName)
                .then()
                .statusCode(OK.value());

        // Updates should eventually cause a cache invalidation, so we must retry<commit_msg>aruha-400 renaming<commit_after>package org.zalando.nakadi.webservice;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Header;
import com.jayway.restassured.specification.RequestSpecification;
import org.echocat.jomon.runtime.concurrent.RetryForSpecifiedTimeStrategy;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.zalando.nakadi.config.JsonConfig;
import org.zalando.nakadi.domain.EventType;
import org.zalando.nakadi.domain.StreamMetadata;
import org.zalando.nakadi.domain.Subscription;
import org.zalando.nakadi.domain.SubscriptionBase;
import org.zalando.nakadi.domain.SubscriptionCursor;
import org.zalando.nakadi.utils.RandomSubscriptionBuilder;
import org.zalando.nakadi.webservice.hila.StreamBatch;
import org.zalando.nakadi.webservice.utils.TestStreamingClient;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

import static com.jayway.restassured.RestAssured.given;
import static com.jayway.restassured.http.ContentType.JSON;
import static java.util.stream.IntStream.rangeClosed;
import static org.echocat.jomon.runtime.concurrent.Retryer.executeWithRetry;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.http.HttpStatus.OK;
import static org.zalando.nakadi.domain.SubscriptionBase.InitialPosition.BEGIN;
import static org.zalando.nakadi.utils.TestUtils.randomTextString;
import static org.zalando.nakadi.utils.TestUtils.randomValidEventTypeName;
import static org.zalando.nakadi.utils.TestUtils.waitFor;
import static org.zalando.nakadi.webservice.hila.StreamBatch.MatcherIgnoringToken.equalToBatchIgnoringToken;
import static org.zalando.nakadi.webservice.utils.NakadiTestUtils.commitCursors;
import static org.zalando.nakadi.webservice.utils.NakadiTestUtils.createSubscription;

public class UserJourneyAT extends RealEnvironmentAT {

    private static final String EVENT1 = "{\"foo\":\"" + randomTextString() + "\"}";
    private static final String EVENT2 = "{\"foo\":\"" + randomTextString() + "\"}";

    private static final ObjectMapper MAPPER = (new JsonConfig()).jacksonObjectMapper();
    private static final String ENDPOINT = "/event-types";

    private String eventTypeName;

    private String eventTypeBody;
    private String eventTypeBodyUpdate;

    @Before
    public void before() throws IOException {
        eventTypeName = randomValidEventTypeName();
        eventTypeBody = getEventTypeJsonFromFile("sample-event-type.json", eventTypeName, owningApp);
        eventTypeBodyUpdate = getEventTypeJsonFromFile("sample-event-type-update.json", eventTypeName, owningApp);
    }

    @SuppressWarnings("unchecked")
    @Test(timeout = 15000)
    public void userJourneyM1() throws InterruptedException, IOException {
        // create event-type
        createEventType();

        // get event type
        jsonRequestSpec()
                .when()
                .get("/event-types/" + eventTypeName)
                .then()
                .statusCode(OK.value())
                .body("name", equalTo(eventTypeName))
                .body("owning_application", equalTo(owningApp))
                .body("category", equalTo("undefined"))
                .body("schema.type", equalTo("json_schema"))
                .body("schema.schema", equalTo("{\"type\": \"object\", \"properties\": " +
                        "{\"foo\": {\"type\": \"string\"}}, \"required\": [\"foo\"]}"));

        // list event types
        jsonRequestSpec()
                .when()
                .get("/event-types")
                .then()
                .statusCode(OK.value())
                .body("size()", Matchers.greaterThan(0))
                .body("name[0]", notNullValue())
                .body("owning_application[0]", notNullValue())
                .body("category[0]", notNullValue())
                .body("schema.type[0]", notNullValue())
                .body("schema.schema[0]", notNullValue());

        final String updateEventTypeBody = getUpdateEventType();

        // update event-type
        jsonRequestSpec()
                .body(updateEventTypeBody)
                .when()
                .put("/event-types/" + eventTypeName)
                .then()
                .statusCode(OK.value());

        // Updates should eventually cause a cache invalidation, so we must retry
{'fraction_non_alphanumeric': 0.11885287286680804, 'fraction_numerical': 0.003130364535999192, 'mean_word_length': 3.415514935354436, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5327391', 'n_tokens_mistral': 2888, 'n_tokens_neox': 2787, 'n_words': 496}