use of com.mongodb.DBCollection 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");
}
use of com.mongodb.DBCollection 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();
}
use of com.mongodb.DBCollection 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();
}
use of com.mongodb.DBCollection in project graylog2-server by Graylog2.
the class ClusterConfigServiceImplTest method removeDoesNothingIfConfigDoesNotExist.
@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void removeDoesNothingIfConfigDoesNotExist() throws Exception {
final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
assertThat(collection.count()).isEqualTo(0L);
assertThat(clusterConfigService.remove(CustomConfig.class)).isEqualTo(0);
}
use of com.mongodb.DBCollection in project graylog2-server by Graylog2.
the class ClusterConfigServiceImplTest method writeUpdatesExistingClusterConfig.
@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void writeUpdatesExistingClusterConfig() throws Exception {
CustomConfig customConfig = new CustomConfig();
customConfig.text = "TEST";
DBObject seedObject = new BasicDBObjectBuilder().add("type", CustomConfig.class.getCanonicalName()).add("payload", Collections.singletonMap("text", "ORIGINAL")).add("last_updated", TIME.toString()).add("last_updated_by", "NOT ID").get();
final DBCollection collection = mongoConnection.getDatabase().getCollection(COLLECTION_NAME);
collection.save(seedObject);
assertThat(collection.count()).isEqualTo(1L);
clusterConfigService.write(customConfig);
assertThat(collection.count()).isEqualTo(1L);
DBObject dbObject = collection.findOne();
assertThat((String) dbObject.get("type")).isEqualTo(CustomConfig.class.getCanonicalName());
assertThat((String) dbObject.get("last_updated_by")).isEqualTo("ID");
@SuppressWarnings("unchecked") Map<String, Object> payload = (Map<String, Object>) dbObject.get("payload");
assertThat(payload).containsEntry("text", "TEST");
}
Aggregations