@Test
  public void testBatchWithoutProject() throws Exception {
    Event.EventContext api = Event.EventContext.apiKey(apiKeys.writeKey());
    ImmutableMap<String, Object> props =
        ImmutableMap.of("test0", "test", "test1", ImmutableList.of("test"), "test2", false);
    byte[] bytes =
        mapper.writeValueAsBytes(
            ImmutableMap.of(
                "api",
                api,
                "events",
                ImmutableList.of(
                    ImmutableMap.of("collection", "test", "properties", props),
                    ImmutableMap.of("collection", "test", "properties", props))));

    EventList events = mapper.readValue(bytes, EventList.class);

    assertEquals("test", events.project);
    assertEquals(api, events.api);

    for (Event event : events.events) {
      assertEquals("test", event.collection());

      assertEquals(eventBuilder.createEvent("test", props).properties(), event.properties());
    }
  }
  @Test
  public void testEmptyMap() throws Exception {
    Event.EventContext api = Event.EventContext.apiKey(apiKeys.writeKey());
    byte[] bytes =
        mapper.writeValueAsBytes(
            ImmutableMap.of(
                "collection",
                "test",
                "api",
                api,
                "properties",
                ImmutableMap.of(
                    "test",
                    1,
                    "test2",
                    new HashMap<String, String>() {
                      {
                        put("a", null);
                      }
                    }),
                "test20",
                ImmutableMap.of(),
                "test3",
                true));

    Event event = mapper.readValue(bytes, Event.class);

    assertEquals("test", event.project());
    assertEquals("test", event.collection());
    assertEquals(api, event.api());
    assertEquals(
        eventBuilder.createEvent("test", ImmutableMap.of("test", 1.0, "test3", true)).properties(),
        event.properties());
  }
  @Test
  public void testInvalidMap() throws Exception {
    Event.EventContext api = Event.EventContext.apiKey(apiKeys.writeKey());
    byte[] bytes =
        mapper.writeValueAsBytes(
            ImmutableMap.of(
                "collection",
                "test",
                "api",
                api,
                "properties",
                ImmutableMap.of("test1", ImmutableMap.of("test", 1, "test2", "test"))));

    Event event = mapper.readValue(bytes, Event.class);

    assertEquals("test", event.project());
    assertEquals("test", event.collection());
    assertEquals(api, event.api());
    assertEquals(
        eventBuilder
            .createEvent(
                "test", ImmutableMap.of("test1", ImmutableMap.of("test", 1.0, "test2", 0.0)))
            .properties(),
        event.properties());
  }
  @Test(expectedExceptions = RakamException.class)
  public void testInvalidField() throws Exception {
    Event.EventContext api = Event.EventContext.apiKey(apiKeys.writeKey());
    byte[] bytes =
        mapper.writeValueAsBytes(
            ImmutableMap.of(
                "collection",
                "test",
                "api",
                api,
                "properties",
                ImmutableMap.of(
                    "test0", "test", "test1", ImmutableList.of("test", "test"), "test2", false),
                "test",
                "test"));

    Event event = mapper.readValue(bytes, Event.class);
    ;

    assertEquals("test", event.project());
    assertEquals("test", event.collection());
    assertEquals(api, event.api());
    assertEquals(
        eventBuilder.createEvent("test", ImmutableMap.of()).properties(), event.properties());
  }
  @Test
  public void testMapType() throws Exception {
    Event.EventContext api = Event.EventContext.apiKey(apiKeys.writeKey());
    ImmutableMap<String, Object> properties =
        ImmutableMap.of(
            "test0",
            "test",
            "test1",
            ImmutableMap.of("a", 4.0, "b", 5.0, "c", 6.0, "d", 7.0),
            "test2",
            false);
    byte[] bytes =
        mapper.writeValueAsBytes(
            ImmutableMap.of(
                "collection", "test",
                "api", api,
                "properties", properties));

    Event event = mapper.readValue(bytes, Event.class);

    assertEquals("test", event.project());
    assertEquals("test", event.collection());
    assertEquals(api, event.api());
    assertEquals(eventBuilder.createEvent("test", properties).properties(), event.properties());
  }
  @Test
  public void testPrimitiveTypes() throws Exception {
    Event.EventContext api = Event.EventContext.apiKey(apiKeys.writeKey());
    ImmutableMap<String, Object> properties =
        ImmutableMap.of(
            "test",
            1L,
            "test1",
            false,
            "test2",
            Instant.now(),
            "test3",
            "test",
            "test4",
            LocalDate.now());

    byte[] bytes =
        mapper.writeValueAsBytes(
            ImmutableMap.of(
                "collection", "test",
                "api", api,
                "properties", properties));

    Event event = mapper.readValue(bytes, Event.class);

    assertEquals("test", event.project());
    assertEquals("test", event.collection());
    assertEquals(api, event.api());
    assertEquals(eventBuilder.createEvent("test", properties).properties(), event.properties());

    assertEquals(
        ImmutableSet.copyOf(metastore.getCollection("test", "test")),
        ImmutableSet.of(
            new SchemaField("test", FieldType.DOUBLE),
            new SchemaField("_user", FieldType.STRING),
            new SchemaField("test1", FieldType.BOOLEAN),
            new SchemaField("test2", FieldType.TIMESTAMP),
            new SchemaField("test3", FieldType.STRING),
            new SchemaField("test4", FieldType.DATE)));
  }
 @AfterMethod
 public void tearDownMethod() throws Exception {
   metastore.deleteProject("test");
   eventDeserializer.cleanCache();
   eventBuilder.cleanCache();
 }