Пример #1
0
  @Test
  public void testObjectSentToScalarValue() throws Exception {
    metastore.getOrCreateCollectionFields(
        "test", "test", ImmutableSet.of(new SchemaField("test", FieldType.STRING)));

    Event.EventContext api = Event.EventContext.apiKey(apiKeys.writeKey());
    ImmutableMap<String, Object> props = ImmutableMap.of("test", ImmutableList.of("test"));
    byte[] bytes =
        mapper.writeValueAsBytes(
            ImmutableMap.of(
                "api", api,
                "collection", "test",
                "properties", props));

    Event events = mapper.readValue(bytes, Event.class);
    assertEquals(events.properties().get("test"), "[\"test\"]");
  }
Пример #2
0
  @Test(
      expectedExceptions = JsonMappingException.class,
      expectedExceptionsMessageRegExp = "Cannot cast object to INTEGER for 'test' field.*")
  public void testObjectSentToInvalidScalarValue() throws Exception {
    metastore.getOrCreateCollectionFields(
        "test", "test", ImmutableSet.of(new SchemaField("test", FieldType.INTEGER)));

    Event.EventContext api = Event.EventContext.apiKey(apiKeys.writeKey());
    ImmutableMap<String, Object> props = ImmutableMap.of("test", ImmutableList.of("test"));
    byte[] bytes =
        mapper.writeValueAsBytes(
            ImmutableMap.of(
                "api", api,
                "collection", "test",
                "properties", props));

    mapper.readValue(bytes, Event.class);
  }
Пример #3
0
  @Test(
      expectedExceptions = JsonMappingException.class,
      expectedExceptionsMessageRegExp =
          "Scalar value 'test' cannot be cast to ARRAY_BOOLEAN type for 'test' field.*")
  public void testScalarSentToObjectValue() throws Exception {
    metastore.getOrCreateCollectionFields(
        "test", "test", ImmutableSet.of(new SchemaField("test", FieldType.ARRAY_BOOLEAN)));

    Event.EventContext api = Event.EventContext.apiKey(apiKeys.writeKey());
    ImmutableMap<String, Object> props = ImmutableMap.of("test", "test");
    byte[] bytes =
        mapper.writeValueAsBytes(
            ImmutableMap.of(
                "api", api,
                "collection", "test",
                "properties", props));

    mapper.readValue(bytes, Event.class);
  }
Пример #4
0
  @Test
  public void testNullSentToObjectValue() throws Exception {
    metastore.getOrCreateCollectionFields(
        "test", "test", ImmutableSet.of(new SchemaField("test", FieldType.ARRAY_BOOLEAN)));

    Event.EventContext api = Event.EventContext.apiKey(apiKeys.writeKey());

    HashMap<String, Object> props = new HashMap<>();
    props.put("test", null);

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

    Event event = mapper.readValue(bytes, Event.class);
    assertNull(event.properties().get("test"));
  }
Пример #5
0
  @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)));
  }
Пример #6
0
 @BeforeMethod
 public void setupMethod() throws Exception {
   metastore.createProject("test");
   apiKeys = apiKeyService.createApiKeys("test");
 }
Пример #7
0
 @AfterMethod
 public void tearDownMethod() throws Exception {
   metastore.deleteProject("test");
   eventDeserializer.cleanCache();
   eventBuilder.cleanCache();
 }