-
Notifications
You must be signed in to change notification settings - Fork 1k
/
InMemorySearchJobServiceTest.java
69 lines (59 loc) · 3.18 KB
/
InMemorySearchJobServiceTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.graylog.plugins.enterprise.search.db;
import com.codahale.metrics.json.MetricsModule;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.google.common.collect.ImmutableMap;
import org.graylog.plugins.enterprise.search.elasticsearch.ElasticsearchQueryString;
import org.graylog.plugins.enterprise.search.filter.StreamFilter;
import org.graylog.plugins.enterprise.search.searchtypes.DateHistogram;
import org.graylog.plugins.enterprise.search.searchtypes.MessageList;
import org.graylog2.database.ObjectIdSerializer;
import org.graylog2.jackson.JodaTimePeriodKeyDeserializer;
import org.graylog2.shared.jackson.SizeSerializer;
import org.graylog2.shared.rest.RangeJsonSerializer;
import org.joda.time.Period;
import org.junit.Test;
import java.util.concurrent.TimeUnit;
public class InMemorySearchJobServiceTest {
private ObjectMapper objectMapper;
@Test
public void setup() throws Exception {
final ObjectMapper mapper = new ObjectMapper();
final TypeFactory typeFactory = mapper.getTypeFactory().withClassLoader(this.getClass().getClassLoader());
this.objectMapper = mapper
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
.setPropertyNamingStrategy(new PropertyNamingStrategy.SnakeCaseStrategy())
.setTypeFactory(typeFactory)
.registerModule(new GuavaModule())
.registerModule(new JodaModule())
.registerModule(new Jdk8Module())
.registerModule(new JavaTimeModule())
.registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false))
.registerModule(new SimpleModule("Graylog")
.addKeyDeserializer(Period.class, new JodaTimePeriodKeyDeserializer())
.addSerializer(new RangeJsonSerializer())
.addSerializer(new SizeSerializer())
.addSerializer(new ObjectIdSerializer()));
// kludge because we don't have an injector in tests
ImmutableMap<String, Class> subtypes = ImmutableMap.<String, Class>builder()
.put(StreamFilter.NAME, StreamFilter.class)
.put(ElasticsearchQueryString.NAME, ElasticsearchQueryString.class)
.put(MessageList.NAME, MessageList.class)
.put(DateHistogram.NAME, DateHistogram.class)
.build();
subtypes.forEach((name, klass) -> objectMapper.registerSubtypes(new NamedType(klass, name)));
}
@Test
public void create() {
}
}