Search in sources :

Example 31 with UsingDataSet

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

the class ClusterConfigServiceImplTest method listReturnsAllClasses.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void listReturnsAllClasses() throws Exception {
    final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
    collection.save(new BasicDBObjectBuilder().add("type", CustomConfig.class.getCanonicalName()).add("payload", Collections.singletonMap("text", "TEST")).add("last_updated", TIME.toString()).add("last_updated_by", "ID").get());
    collection.save(new BasicDBObjectBuilder().add("type", AnotherCustomConfig.class.getCanonicalName()).add("payload", Collections.singletonMap("text", "TEST")).add("last_updated", TIME.toString()).add("last_updated_by", "ID").get());
    assertThat(collection.count()).isEqualTo(2L);
    assertThat(clusterConfigService.list()).hasSize(2).containsOnly(CustomConfig.class, AnotherCustomConfig.class);
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 32 with UsingDataSet

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

the class ClusterConfigServiceImplTest method getReturnsExistingConfig.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void getReturnsExistingConfig() throws Exception {
    DBObject dbObject = new BasicDBObjectBuilder().add("type", CustomConfig.class.getCanonicalName()).add("payload", Collections.singletonMap("text", "TEST")).add("last_updated", TIME.toString()).add("last_updated_by", "ID").get();
    final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
    collection.save(dbObject);
    assertThat(collection.count()).isEqualTo(1L);
    CustomConfig customConfig = clusterConfigService.get(CustomConfig.class);
    assertThat(customConfig.text).isEqualTo("TEST");
}
Also used : DBCollection(com.mongodb.DBCollection) BasicDBObjectBuilder(com.mongodb.BasicDBObjectBuilder) DBObject(com.mongodb.DBObject) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 33 with UsingDataSet

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

the class NodeServiceImplTest method testRegisterServerWithExistingNode.

@Test
@UsingDataSet(locations = "NodeServiceImplTest-one-node.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testRegisterServerWithExistingNode() throws Exception {
    final Node node1 = nodeService.byNodeId(nodeId);
    assertThat(node1.getNodeId()).describedAs("There should be one existing node").isEqualTo(NODE_ID);
    nodeService.registerServer(nodeId.toString(), true, TRANSPORT_URI, LOCAL_CANONICAL_HOSTNAME);
    final DBCollection collection = mongoRule.getMongoConnection().getDatabase().getCollection("nodes");
    assertThat(collection.count()).describedAs("There should only be one node").isEqualTo(1);
    final Node node2 = nodeService.byNodeId(nodeId);
    assertThat(node2).isNotNull();
    assertThat(node2.getHostname()).isEqualTo(LOCAL_CANONICAL_HOSTNAME);
    assertThat(node2.getTransportAddress()).isEqualTo(TRANSPORT_URI.toString());
    assertThat(node2.isMaster()).isTrue();
}
Also used : DBCollection(com.mongodb.DBCollection) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 34 with UsingDataSet

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

the class LdapSettingsServiceImplTest method loadReturnNullIfPasswordSecretIsWrong.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.CLEAN_INSERT, locations = "LdapSettingsServiceImplTest-invalid-password.json")
public void loadReturnNullIfPasswordSecretIsWrong() throws Exception {
    final LdapSettings ldapSettings = ldapSettingsService.load();
    assertThat(ldapSettings).isNull();
}
Also used : LdapSettings(org.graylog2.shared.security.ldap.LdapSettings) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 35 with UsingDataSet

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

the class ClusterConfigServiceImplTest method getWithKeyReturnsNullOnNonExistingConfig.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void getWithKeyReturnsNullOnNonExistingConfig() throws Exception {
    final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
    assertThat(collection.count()).isEqualTo(0L);
    assertThat(clusterConfigService.get("foo", CustomConfig.class)).isNull();
}
Also used : DBCollection(com.mongodb.DBCollection) 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