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));
}
}
}
Aggregations