Search in sources :

Example 1 with GranularityType

use of org.apache.druid.java.util.common.granularity.GranularityType in project druid by druid-io.

the class QueryGranularityTest method testStandardGranularitiesSerde.

@Test
public void testStandardGranularitiesSerde() throws Exception {
    ObjectMapper mapper = new DefaultObjectMapper();
    for (GranularityType granularityType : GranularityType.values()) {
        final Granularity granularity = granularityType.getDefaultGranularity();
        Assert.assertEquals(granularity, mapper.readValue("\"" + StringUtils.toUpperCase(granularityType.name()) + "\"", Granularity.class));
        Assert.assertEquals(granularity, mapper.readValue("\"" + StringUtils.toLowerCase(granularityType.name()) + "\"", Granularity.class));
        Assert.assertEquals(granularity, mapper.readValue(mapper.writeValueAsString(granularity), Granularity.class));
        if (granularityType == GranularityType.ALL || granularityType == GranularityType.NONE) {
            Assert.assertEquals("{\"type\":\"" + StringUtils.toLowerCase(granularityType.name()) + "\"}", mapper.writeValueAsString(granularity));
        } else {
            Assert.assertEquals("\"" + StringUtils.toUpperCase(granularityType.name()) + "\"", mapper.writeValueAsString(granularity));
        }
    }
}
Also used : GranularityType(org.apache.druid.java.util.common.granularity.GranularityType) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Granularity(org.apache.druid.java.util.common.granularity.Granularity) PeriodGranularity(org.apache.druid.java.util.common.granularity.PeriodGranularity) DurationGranularity(org.apache.druid.java.util.common.granularity.DurationGranularity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)1 DurationGranularity (org.apache.druid.java.util.common.granularity.DurationGranularity)1 Granularity (org.apache.druid.java.util.common.granularity.Granularity)1 GranularityType (org.apache.druid.java.util.common.granularity.GranularityType)1 PeriodGranularity (org.apache.druid.java.util.common.granularity.PeriodGranularity)1 Test (org.junit.Test)1