use of org.apache.druid.jackson.DefaultObjectMapper 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));
}
}
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class QueryGranularityTest method testSerializePeriod.
@Test
public void testSerializePeriod() throws Exception {
final ObjectMapper mapper = new DefaultObjectMapper();
String json = "{ \"type\": \"period\", \"period\": \"P1D\" }";
Granularity gran = mapper.readValue(json, Granularity.class);
Assert.assertEquals(new PeriodGranularity(new Period("P1D"), null, null), gran);
// Nonstandard period
json = "{ \"type\": \"period\", \"period\": \"P2D\" }";
gran = mapper.readValue(json, Granularity.class);
Assert.assertEquals(new PeriodGranularity(new Period("P2D"), null, null), gran);
// Set timeZone, origin
json = "{ \"type\": \"period\", \"period\": \"P1D\"," + "\"timeZone\": \"America/Los_Angeles\", \"origin\": \"1970-01-01T00:00:00Z\"}";
gran = mapper.readValue(json, Granularity.class);
Assert.assertEquals(new PeriodGranularity(new Period("P1D"), DateTimes.EPOCH, DateTimes.inferTzFromString("America/Los_Angeles")), gran);
PeriodGranularity expected = new PeriodGranularity(new Period("P1D"), DateTimes.of("2012-01-01"), DateTimes.inferTzFromString("America/Los_Angeles"));
String jsonOut = mapper.writeValueAsString(expected);
Assert.assertEquals(expected, mapper.readValue(jsonOut, Granularity.class));
String illegalJson = "{ \"type\": \"period\", \"period\": \"P0D\" }";
try {
mapper.readValue(illegalJson, Granularity.class);
Assert.fail();
} catch (JsonMappingException e) {
}
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class PreResponseAuthorizationCheckFilterTest method testValidRequest.
@Test
public void testValidRequest() throws Exception {
AuthenticationResult authenticationResult = new AuthenticationResult("so-very-valid", "so-very-valid", null, null);
HttpServletRequest req = EasyMock.createStrictMock(HttpServletRequest.class);
HttpServletResponse resp = EasyMock.createStrictMock(HttpServletResponse.class);
FilterChain filterChain = EasyMock.createNiceMock(FilterChain.class);
ServletOutputStream outputStream = EasyMock.createNiceMock(ServletOutputStream.class);
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(authenticationResult).once();
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(true).once();
EasyMock.replay(req, resp, filterChain, outputStream);
PreResponseAuthorizationCheckFilter filter = new PreResponseAuthorizationCheckFilter(authenticators, new DefaultObjectMapper());
filter.doFilter(req, resp, filterChain);
EasyMock.verify(req, resp, filterChain, outputStream);
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class FakeQuery method testNestedQueryLoggingMDC.
@Test
public void testNestedQueryLoggingMDC() throws Exception {
final LoggingRequestLogger requestLogger = new LoggingRequestLogger(new DefaultObjectMapper(), true, false);
requestLogger.logNativeQuery(RequestLogLine.forNative(nestedQuery, timestamp, remoteAddr, queryStats));
final Map<String, Object> map = readContextMap(BAOS.toByteArray());
Assert.assertEquals("datasource", map.get("dataSource"));
Assert.assertEquals("PT86400S", map.get("duration"));
Assert.assertEquals("false", map.get("hasFilters"));
Assert.assertEquals("fake", map.get("queryType"));
Assert.assertEquals("some.host.tld", map.get("remoteAddr"));
Assert.assertEquals("false", map.get("descending"));
Assert.assertEquals("true", map.get("isNested"));
Assert.assertNull(map.get("foo"));
}
use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class FakeQuery method testUnionQueryLoggingMDC.
@Test
public void testUnionQueryLoggingMDC() throws Exception {
final LoggingRequestLogger requestLogger = new LoggingRequestLogger(new DefaultObjectMapper(), true, false);
requestLogger.logNativeQuery(RequestLogLine.forNative(unionQuery, timestamp, remoteAddr, queryStats));
final Map<String, Object> map = readContextMap(BAOS.toByteArray());
Assert.assertEquals("A,B", map.get("dataSource"));
Assert.assertEquals("true", map.get("isNested"));
Assert.assertEquals("PT86400S", map.get("duration"));
Assert.assertEquals("false", map.get("hasFilters"));
Assert.assertEquals("fake", map.get("queryType"));
Assert.assertEquals("some.host.tld", map.get("remoteAddr"));
Assert.assertEquals("false", map.get("descending"));
Assert.assertNull(map.get("foo"));
}
Aggregations