// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java
// public interface ResourceStatus {
// 
//   Resource getResource();
// 
//   void setResource(Resource resource);
// 
//   Status getStatus();
// 
//   void setStatus(Status status);
// 
//   Date getUpdated();
// 
//   void setUpdated(Date updated);
// }
// 
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java
// public class MongoConnector {
// 
//   private final static String MONITOR_DB = "monitor_tmp_newDomain";
//   private final static Logger log = Logger.getLogger(MongoConnector.class);
//   private static MongoConnector connector;
// 
//   private MongoDatabase db;
//   private MongoClient client;
// 
// 
//   private MongoConnector() throws DiagnosticException {
//     client = new MongoClient();
//     db = client.getDatabase(MONITOR_DB);
// 
//   }
// 
//   private MongoConnector(String connectURIStr) throws DiagnosticException {
//     MongoClientURI clientURI = new MongoClientURI(connectURIStr);
//     client = new MongoClient(clientURI);
//     String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase();
//     db = client.getDatabase(dbName);
// 
//   }
// 
//   public static MongoConnector getInstance() {
//     if (connector == null) {
//       try {
//         String mongoConnectURI = System.getProperty("mongo.connect.uri", null);
//         if (mongoConnectURI == null)
//           connector = new MongoConnector();
//         else
//           connector = new MongoConnector(mongoConnectURI);
//       } catch (Exception e) {
//         log.error("Exception on mongoDB connection creation. ", e);
//         throw new RuntimeException(e);
//       }
//     }
//     return connector;
//   }
// 
// 
//   public ResourceLastStatusDAO getLastStatusDAO() {
//     return new ResourceLastStatusDAO(db);
//   }
// 
//   public ResourceStatusDetailDAO getMonthDetailDAO() {
//     return new ResourceStatusDetailDAO(db);
//   }
// 
//   public AggregatedStatusDAO getAggregatedStatusDAO() {
//     return new AggregatedStatusDAO(db);
//   }
// 
//   public ResourceDAO getResourceDAO() {
//     return new ResourceDAO(db);
//   }
// 
// 
//   public void close() {
//     client.close();
//     connector = null;
//   }
// 
// 
// }
// 
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceLastStatusDAO.java
// public class ResourceLastStatusDAO extends AbstractDAO {
// 
//   private final static String COLLECTION_NAME = "ResourceLastStatus";
//   private MongoCollection<Document> thisCollection;
// 
// 
//   public ResourceLastStatusDAO(MongoDatabase db) {
//     super(db);
//     thisCollection = db.getCollection(COLLECTION_NAME);
//   }
// 
// 
//   /**
//    * Remove all last statuses for particular environment
//    * @param environmentName name of environment to remove statuses for
//    */
//   public void delete(String environmentName) {
//     thisCollection.deleteMany(eq("environmentName", environmentName));
//   }
// 
// 
//   /**
//    * Replace existing last statuses for environment by new ones
//    * @param environmentName environment to update statuses
//    * @param resources       new statuses to be set up
//    */
//   public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resources) {
//     delete(environmentName);
// 
//     List<Document> dbResources = resources.stream()
//         .map(rs -> DocumentMapper.resourceStatusToDocument(environmentName, rs))
//         .collect(Collectors.toList());
// 
//     thisCollection.insertMany(dbResources);
//   }
// 
// 
//   /**
//    * Get last statuses for environment resources
//    * @param environmentName environment to fetch statuses for
//    */
//   public List<ResourceStatus> find(String environmentName) {
//     List<ResourceStatus> resources = thisCollection.find(new Document().append("environmentName", environmentName))
//         .map(DocumentMapper::resourceStatusFromDocument)
//         .into(new ArrayList<>());
// 
//     return resources;
//   }
// 
// 
//   /**
//    * Get last statuses for multiple environments
//    *
//    * @param environmentNames environments to fetch statuses for
//    * @return
//    */
//   public List<ResourceStatus> find(Collection<String> environmentNames) {
//     List<ResourceStatus> resources = thisCollection.find(in("environmentName", environmentNames))
//         .map(DocumentMapper::resourceStatusFromDocument)
//         .into(new ArrayList<>());
// 
//     return resources;
//   }
// 
// 
//   /**
//    * Get last statuses for particular environment and defined resources
//    * @param environmentName environment to fetch statuses for
//    * @param resourceIds resources to fetch statuses for
//    * @return
//    */
//   public List<ResourceStatus> find(String environmentName, Set<String> resourceIds) {
//     Bson query = and(
//         eq("environmentName", environmentName),
//         in("resource.resourceId", resourceIds)
//     );
// 
//     List<ResourceStatus> resources = thisCollection.find(query)
//         .map(DocumentMapper::resourceStatusFromDocument)
//         .into(new ArrayList<>());
// 
//     return resources;
//   }
// 
// }


import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.yagel.monitor.ResourceStatus;
import org.yagel.monitor.mongo.MongoConnector;
import org.yagel.monitor.mongo.ResourceLastStatusDAO;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
package org.yagel.monitor.runner.test.intergation.dao;



public class ResourceLastStatusDAOTest extends AbstractDAOTest {

  private ResourceLastStatusDAO lastStatusDAO;
  private String environmentName = this.getClass().getSimpleName();
  private int resourcesCount = 5;

  @BeforeClass
  public void loadDao() throws Exception {
    lastStatusDAO = MongoConnector.getInstance().getLastStatusDAO();
  }

  @Test
  public void testInsertFindMultiple() throws Exception {
// Path: environment.monitor.core/src/main/java/org/yagel/monitor/ResourceStatus.java
// public interface ResourceStatus {
// 
//   Resource getResource();
// 
//   void setResource(Resource resource);
// 
//   Status getStatus();
// 
//   void setStatus(Status status);
// 
//   Date getUpdated();
// 
//   void setUpdated(Date updated);
// }
// 
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/MongoConnector.java
// public class MongoConnector {
// 
//   private final static String MONITOR_DB = "monitor_tmp_newDomain";
//   private final static Logger log = Logger.getLogger(MongoConnector.class);
//   private static MongoConnector connector;
// 
//   private MongoDatabase db;
//   private MongoClient client;
// 
// 
//   private MongoConnector() throws DiagnosticException {
//     client = new MongoClient();
//     db = client.getDatabase(MONITOR_DB);
// 
//   }
// 
//   private MongoConnector(String connectURIStr) throws DiagnosticException {
//     MongoClientURI clientURI = new MongoClientURI(connectURIStr);
//     client = new MongoClient(clientURI);
//     String dbName = clientURI.getDatabase() == null ? MONITOR_DB : clientURI.getDatabase();
//     db = client.getDatabase(dbName);
// 
//   }
// 
//   public static MongoConnector getInstance() {
//     if (connector == null) {
//       try {
//         String mongoConnectURI = System.getProperty("mongo.connect.uri", null);
//         if (mongoConnectURI == null)
//           connector = new MongoConnector();
//         else
//           connector = new MongoConnector(mongoConnectURI);
//       } catch (Exception e) {
//         log.error("Exception on mongoDB connection creation. ", e);
//         throw new RuntimeException(e);
//       }
//     }
//     return connector;
//   }
// 
// 
//   public ResourceLastStatusDAO getLastStatusDAO() {
//     return new ResourceLastStatusDAO(db);
//   }
// 
//   public ResourceStatusDetailDAO getMonthDetailDAO() {
//     return new ResourceStatusDetailDAO(db);
//   }
// 
//   public AggregatedStatusDAO getAggregatedStatusDAO() {
//     return new AggregatedStatusDAO(db);
//   }
// 
//   public ResourceDAO getResourceDAO() {
//     return new ResourceDAO(db);
//   }
// 
// 
//   public void close() {
//     client.close();
//     connector = null;
//   }
// 
// 
// }
// 
// Path: environment.monitor.runner/src/main/java/org/yagel/monitor/mongo/ResourceLastStatusDAO.java
// public class ResourceLastStatusDAO extends AbstractDAO {
// 
//   private final static String COLLECTION_NAME = "ResourceLastStatus";
//   private MongoCollection<Document> thisCollection;
// 
// 
//   public ResourceLastStatusDAO(MongoDatabase db) {
//     super(db);
//     thisCollection = db.getCollection(COLLECTION_NAME);
//   }
// 
// 
//   /**
//    * Remove all last statuses for particular environment
//    * @param environmentName name of environment to remove statuses for
//    */
//   public void delete(String environmentName) {
//     thisCollection.deleteMany(eq("environmentName", environmentName));
//   }
// 
// 
//   /**
//    * Replace existing last statuses for environment by new ones
//    * @param environmentName environment to update statuses
//    * @param resources       new statuses to be set up
//    */
//   public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resources) {
//     delete(environmentName);
// 
//     List<Document> dbResources = resources.stream()
//         .map(rs -> DocumentMapper.resourceStatusToDocument(environmentName, rs))
//         .collect(Collectors.toList());
// 
//     thisCollection.insertMany(dbResources);
//   }
// 
// 
//   /**
//    * Get last statuses for environment resources
//    * @param environmentName environment to fetch statuses for
//    */
//   public List<ResourceStatus> find(String environmentName) {
//     List<ResourceStatus> resources = thisCollection.find(new Document().append("environmentName", environmentName))
//         .map(DocumentMapper::resourceStatusFromDocument)
//         .into(new ArrayList<>());
// 
//     return resources;
//   }
// 
// 
//   /**
//    * Get last statuses for multiple environments
//    *
//    * @param environmentNames environments to fetch statuses for
//    * @return
//    */
//   public List<ResourceStatus> find(Collection<String> environmentNames) {
//     List<ResourceStatus> resources = thisCollection.find(in("environmentName", environmentNames))
//         .map(DocumentMapper::resourceStatusFromDocument)
//         .into(new ArrayList<>());
// 
//     return resources;
//   }
// 
// 
//   /**
//    * Get last statuses for particular environment and defined resources
//    * @param environmentName environment to fetch statuses for
//    * @param resourceIds resources to fetch statuses for
//    * @return
//    */
//   public List<ResourceStatus> find(String environmentName, Set<String> resourceIds) {
//     Bson query = and(
//         eq("environmentName", environmentName),
//         in("resource.resourceId", resourceIds)
//     );
// 
//     List<ResourceStatus> resources = thisCollection.find(query)
//         .map(DocumentMapper::resourceStatusFromDocument)
//         .into(new ArrayList<>());
// 
//     return resources;
//   }
// 
// }


// Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/ResourceLastStatusDAOTest.java
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.yagel.monitor.ResourceStatus;
import org.yagel.monitor.mongo.MongoConnector;
import org.yagel.monitor.mongo.ResourceLastStatusDAO;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

package org.yagel.monitor.runner.test.intergation.dao;



public class ResourceLastStatusDAOTest extends AbstractDAOTest {

  private ResourceLastStatusDAO lastStatusDAO;
  private String environmentName = this.getClass().getSimpleName();
  private int resourcesCount = 5;

  @BeforeClass
  public void loadDao() throws Exception {
    lastStatusDAO = MongoConnector.getInstance().getLastStatusDAO();
  }

  @Test
  public void testInsertFindMultiple() throws Exception {
    List<ResourceStatus> statusList = generateN(resourcesCount, this::rndResStatus);