Search in sources :

Example 41 with ObjectMapperProvider

use of org.graylog2.shared.bindings.providers.ObjectMapperProvider in project graylog2-server by Graylog2.

the class MongoIndexSetServiceTest method setUp.

@Before
public void setUp() throws Exception {
    clusterEventBus = new ClusterEventBus();
    clusterConfigService = new ClusterConfigServiceImpl(objectMapperProvider, mongodb.mongoConnection(), nodeId, new ChainingClassLoader(getClass().getClassLoader()), clusterEventBus);
    indexSetService = new MongoIndexSetService(mongodb.mongoConnection(), objectMapperProvider, streamService, clusterConfigService, clusterEventBus);
}
Also used : ClusterConfigServiceImpl(org.graylog2.cluster.ClusterConfigServiceImpl) ClusterEventBus(org.graylog2.events.ClusterEventBus) ChainingClassLoader(org.graylog2.shared.plugins.ChainingClassLoader) Before(org.junit.Before)

Example 42 with ObjectMapperProvider

use of org.graylog2.shared.bindings.providers.ObjectMapperProvider in project graylog2-server by Graylog2.

the class DeletionRetentionStrategyConfigTest method testSerialization.

@Test
public void testSerialization() throws JsonProcessingException {
    final DeletionRetentionStrategyConfig config = DeletionRetentionStrategyConfig.create(25);
    final ObjectMapper objectMapper = new ObjectMapperProvider().get();
    final String json = objectMapper.writeValueAsString(config);
    final Object document = Configuration.defaultConfiguration().jsonProvider().parse(json);
    assertThat((String) JsonPath.read(document, "$.type")).isEqualTo("org.graylog2.indexer.retention.strategies.DeletionRetentionStrategyConfig");
    assertThat((Integer) JsonPath.read(document, "$.max_number_of_indices")).isEqualTo(25);
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Test(org.junit.Test)

Example 43 with ObjectMapperProvider

use of org.graylog2.shared.bindings.providers.ObjectMapperProvider in project graylog2-server by Graylog2.

the class SizeBasedRotationStrategyConfigTest method testSerialization.

@Test
public void testSerialization() throws JsonProcessingException {
    final RotationStrategyConfig config = SizeBasedRotationStrategyConfig.create(1000L);
    final ObjectMapper objectMapper = new ObjectMapperProvider().get();
    final String json = objectMapper.writeValueAsString(config);
    final Object document = Configuration.defaultConfiguration().jsonProvider().parse(json);
    assertThat((String) JsonPath.read(document, "$.type")).isEqualTo("org.graylog2.indexer.rotation.strategies.SizeBasedRotationStrategyConfig");
    assertThat((Integer) JsonPath.read(document, "$.max_size")).isEqualTo(1000);
}
Also used : RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Test(org.junit.Test)

Example 44 with ObjectMapperProvider

use of org.graylog2.shared.bindings.providers.ObjectMapperProvider in project graylog2-server by Graylog2.

the class SizeBasedRotationStrategyConfigTest method testDeserialization.

@Test
public void testDeserialization() throws IOException {
    final ObjectMapper objectMapper = new ObjectMapperProvider().get();
    final String json = "{ \"type\": \"org.graylog2.indexer.rotation.strategies.SizeBasedRotationStrategyConfig\", \"max_size\": 1000 }";
    final RotationStrategyConfig config = objectMapper.readValue(json, RotationStrategyConfig.class);
    assertThat(config).isInstanceOf(SizeBasedRotationStrategyConfig.class);
    assertThat(((SizeBasedRotationStrategyConfig) config).maxSize()).isEqualTo(1000);
}
Also used : RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Test(org.junit.Test)

Example 45 with ObjectMapperProvider

use of org.graylog2.shared.bindings.providers.ObjectMapperProvider in project graylog2-server by Graylog2.

the class TimeBasedRotationStrategyConfigTest method testDeserializationWithMissingProperty.

@Test
public void testDeserializationWithMissingProperty() throws IOException {
    final ObjectMapper objectMapper = new ObjectMapperProvider().get();
    final String json = "{ \"type\": \"org.graylog2.indexer.rotation.strategies.TimeBasedRotationStrategyConfig\", \"rotation_period\": \"P1D\"}";
    final RotationStrategyConfig config = objectMapper.readValue(json, RotationStrategyConfig.class);
    assertThat(config).isInstanceOf(TimeBasedRotationStrategyConfig.class);
    assertThat(((TimeBasedRotationStrategyConfig) config).rotationPeriod()).isEqualTo(Period.days(1));
    assertNull(((TimeBasedRotationStrategyConfig) config).maxRotationPeriod());
}
Also used : RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Test(org.junit.Test)

Aggregations

ObjectMapperProvider (org.graylog2.shared.bindings.providers.ObjectMapperProvider)45 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)38 Before (org.junit.Before)32 MongoJackObjectMapperProvider (org.graylog2.bindings.providers.MongoJackObjectMapperProvider)24 Test (org.junit.Test)18 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)7 RotationStrategyConfig (org.graylog2.plugin.indexer.rotation.RotationStrategyConfig)7 ClusterEventBus (org.graylog2.events.ClusterEventBus)5 JobSchedulerTestClock (org.graylog.events.JobSchedulerTestClock)4 ClusterConfigServiceImpl (org.graylog2.cluster.ClusterConfigServiceImpl)4 ChainingClassLoader (org.graylog2.shared.plugins.ChainingClassLoader)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 TestEventProcessorConfig (org.graylog.events.TestEventProcessorConfig)3 DBEventDefinitionService (org.graylog.events.processor.DBEventDefinitionService)3 IntervalJobSchedule (org.graylog.scheduler.schedule.IntervalJobSchedule)3 MongoConnection (org.graylog2.database.MongoConnection)3 AutoValueSubtypeResolver (org.graylog2.jackson.AutoValueSubtypeResolver)3 StreamService (org.graylog2.streams.StreamService)3 Mockito.mock (org.mockito.Mockito.mock)3 ImmutableMap (com.google.common.collect.ImmutableMap)2