MongoStorage implements Storage { @Override public QueryAnswer query(Query query) { QueryRedactor queryRedactor; switch (query.getType()) { case FETCH: queryRedactor = queryRedactorFactory.fetch(query.getEntityID()); break; case DELETE: queryRedactor = queryRedactorFactory.delete(query.getEntityID()); break; default: return QueryAnswerFactory.badQuery(); } try { queryTranslator.interpret(query, queryRedactor); } catch (DAOException e) { log.error("Unsupported query '{}'", query, e); return QueryAnswerFactory.badQuery(); } final QueryExecutor queryExecutor; try { queryExecutor = queryExecutorFactory.createExecutor(queryRedactor); } catch (DAOException e) { log.error("Query '{}' is invalid.", query, e); return QueryAnswerFactory.badQuery(); } try { return queryExecutor.execute(); } catch (QueryExecutionException e) { log.error("Failed to execute query '{}': {}", query, e); return QueryAnswerFactory.queryExecutionFailed(); } catch (MongoException e) { if (e instanceof MongoException.Network) { return QueryAnswerFactory.persistenceDown(); } else { log.error("Unknown MongoDB exception processing query '{}'", query, e); return QueryAnswerFactory.unknownError(); } } catch (Throwable t) { log.error("Unknown error processing query '{}'", query, t); return QueryAnswerFactory.unknownError(); } } private  MongoStorage(MongoClient client, String dbname); private  MongoStorage(MongoClient client, String dbname, String username, String password); static MongoStorage create(String hostname, String dbname, MongoClientOptions opts); static MongoStorage create(List<ServerAddress> seeds, String dbname, MongoClientOptions opts); static MongoStorage create(String hostname, String dbname, String username, String password,
			MongoClientOptions opts); static MongoStorage create(List<ServerAddress> seeds, String dbname, String username, String password,
			MongoClientOptions opts); @Override void start(); @Override void stop(); @Override void store(EntityID entityId, String entityJSON); @Override SuccessAction<EntityCarrier> createPersistAction(); @Override QueryAnswer query(Query query); @Override boolean isConnected(); @Override boolean isIdle();  }
@Test public void testRetrieveFromInexistentCollection() { assertEquals(0, storage.query(new QueryBuilder().on(dummyId).with("something", "strange").fetch()).getData().size()); }
@Test public void testFetchQuery_dbDown() { final QueryAnswer answer = storage.query(new QueryBuilder().on(dummyId).fetch()); assertEquals(QueryStatus.PERSISTENCE_DOWN, answer.getStatus()); }