Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test proper deserialization of blacklist filters.
- Loading branch information
1 parent
54c6ff0
commit 8ce0c7c
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
graylog2-server/src/test/java/org/graylog2/filters/FilterServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.graylog2.filters; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.lordofthejars.nosqlunit.annotation.UsingDataSet; | ||
import com.lordofthejars.nosqlunit.core.LoadStrategyEnum; | ||
import com.lordofthejars.nosqlunit.mongodb.InMemoryMongoDb; | ||
import org.graylog2.bindings.providers.MongoJackObjectMapperProvider; | ||
import org.graylog2.bindings.providers.ServerObjectMapperProvider; | ||
import org.graylog2.database.MongoConnectionRule; | ||
import org.graylog2.filters.blacklist.BlacklistPatternCondition; | ||
import org.graylog2.filters.blacklist.FilterDescription; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.util.Set; | ||
|
||
import static com.lordofthejars.nosqlunit.mongodb.InMemoryMongoDb.InMemoryMongoRuleBuilder.newInMemoryMongoDbRule; | ||
import static org.assertj.core.api.Assertions.*; | ||
|
||
public class FilterServiceImplTest { | ||
@ClassRule | ||
public static final InMemoryMongoDb IN_MEMORY_MONGO_DB = newInMemoryMongoDbRule().build(); | ||
|
||
@Rule | ||
public MongoConnectionRule mongoRule = MongoConnectionRule.build("test"); | ||
|
||
private FilterService filterService; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
final ObjectMapper objectMapper = new ServerObjectMapperProvider().get(); | ||
this.filterService = new FilterServiceImpl(mongoRule.getMongoConnection(), new MongoJackObjectMapperProvider(objectMapper)); | ||
} | ||
|
||
@Test | ||
@UsingDataSet(locations = "properDeserializationOfSubclasses.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT) | ||
public void testProperDeserializationOfSubclasses() throws Exception { | ||
final Set<FilterDescription> filterDescriptionSet = filterService.loadAll(); | ||
assertThat(filterDescriptionSet).isNotNull().hasSize(1); | ||
|
||
final FilterDescription filterDescription = filterDescriptionSet.iterator().next(); | ||
assertThat(filterDescription).isNotNull(); | ||
assertThat(filterDescription instanceof BlacklistPatternCondition); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...og2-server/src/test/resources/org/graylog2/filters/properDeserializationOfSubclasses.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"filters": [ | ||
{ | ||
"_id": {"$oid": "54e9deadbeefdeadbeefaffe"}, | ||
"type" : "regex", | ||
"creator_user_id" : "admin", | ||
"created_at" : "2015-12-18T12:54:03.911Z", | ||
"name" : "Testfilter", | ||
"description" : "A basic Regex filter for testing", | ||
"field_name" : "message", | ||
"pattern" : "posts" | ||
} | ||
] | ||
} |