Search in sources :

Example 41 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class AlertServiceImplTest method loadRecentOfStreamsFiltersByStream.

@Test
@UsingDataSet(locations = "multiple-alerts.json")
public void loadRecentOfStreamsFiltersByStream() throws Exception {
    final List<Alert> alerts = alertService.loadRecentOfStreams(ImmutableList.of("5666df42bee80072613ce14d", "5666df42bee80072613ce14f"), new DateTime(0L, DateTimeZone.UTC), 300);
    assertThat(alerts.size()).isEqualTo(2);
    assertThat(alerts.get(0).getStreamId()).isNotEqualTo(STREAM_ID);
    assertThat(alerts.get(1).getStreamId()).isNotEqualTo(STREAM_ID);
}
Also used : DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) MongoDBServiceTest(org.graylog2.database.MongoDBServiceTest) Test(org.junit.Test)

Example 42 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class UserServiceImplTest method testSave.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void testSave() throws Exception {
    final User user = userService.create();
    user.setName("TEST");
    user.setFullName("TEST");
    user.setEmail("test@example.com");
    user.setTimeZone(DateTimeZone.UTC);
    user.setPassword("TEST");
    user.setPermissions(Collections.<String>emptyList());
    final String id = userService.save(user);
    final DBObject query = BasicDBObjectBuilder.start("_id", new ObjectId(id)).get();
    final DBObject dbObject = mongoConnection.getDatabase().getCollection(UserImpl.COLLECTION_NAME).findOne(query);
    assertThat(dbObject.get("username")).isEqualTo("TEST");
    assertThat(dbObject.get("full_name")).isEqualTo("TEST");
    assertThat(dbObject.get("email")).isEqualTo("test@example.com");
    assertThat(dbObject.get("timezone")).isEqualTo("UTC");
    assertThat((String) dbObject.get("password")).isNotEmpty();
}
Also used : User(org.graylog2.plugin.database.users.User) ObjectId(org.bson.types.ObjectId) DBObject(com.mongodb.DBObject) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 43 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class UserServiceImplTest method testLoad.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testLoad() throws Exception {
    final User user = userService.load("user1");
    assertThat(user).isNotNull();
    assertThat(user.getName()).isEqualTo("user1");
    assertThat(user.getEmail()).isEqualTo("user1@example.com");
}
Also used : User(org.graylog2.plugin.database.users.User) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 44 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class AbsoluteSearchResourceTest method searchForAllMessages.

@Test
@UsingDataSet(locations = "searchForExistingKeyword.json")
public void searchForAllMessages() {
    final ValidatableResponse result = doSearchFor("*");
    final JsonPath response = result.statusCode(200).extract().jsonPath();
    assertThat(response.getInt("total_results")).isEqualTo(2);
    assertThat(response.getList("messages")).hasSize(2);
    assertThat(response.getList("used_indices")).hasSize(1);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) JsonPath(com.jayway.restassured.path.json.JsonPath) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 45 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class AbsoluteSearchResourceTest method searchForExistingKeywordOutsideOfTimeRange.

@Test
@UsingDataSet(locations = "searchForExistingKeyword.json")
public void searchForExistingKeywordOutsideOfTimeRange() {
    final ValidatableResponse result = doSearchFor("Testmessage", "2015-06-14T11:32:16.827Z", "2015-06-15T11:32:16.827Z");
    final JsonPath response = result.statusCode(200).extract().jsonPath();
    assertThat(response.getInt("total_results")).isEqualTo(0);
    assertThat(response.getList("messages")).isEmpty();
    assertThat(response.getList("used_indices")).hasSize(1);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) JsonPath(com.jayway.restassured.path.json.JsonPath) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Aggregations

UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)94 Test (org.junit.Test)94 DateTime (org.joda.time.DateTime)40 DBCollection (com.mongodb.DBCollection)29 ZonedDateTime (java.time.ZonedDateTime)19 DBObject (com.mongodb.DBObject)15 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)13 ObjectId (org.bson.types.ObjectId)9 MongoDBServiceTest (org.graylog2.database.MongoDBServiceTest)9 Timer (com.codahale.metrics.Timer)6 Histogram (com.codahale.metrics.Histogram)5 JsonPath (com.jayway.restassured.path.json.JsonPath)5 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)5 HistogramResult (org.graylog2.indexer.results.HistogramResult)5 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)5 List (java.util.List)4 TermsResult (org.graylog2.indexer.results.TermsResult)4 User (org.graylog2.plugin.database.users.User)4 LdapSettings (org.graylog2.shared.security.ldap.LdapSettings)4 Map (java.util.Map)3