// 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/ResourceStatusDetailDAO.java
// public class ResourceStatusDetailDAO extends AbstractTimeRangeDAO {
// 
//   public ResourceStatusDetailDAO(MongoDatabase mongoDatabase) {
//     super(mongoDatabase);
//     switchCollection(new Date());
//   }
// 
// 
//   /**
//    * Inserts new resource status into corresponding month collection
//    *
//    * @param environmentName environment resource belongs to
//    * @param resourceStatus  status to be inserted
//    */
//   public synchronized void insert(String environmentName, ResourceStatus resourceStatus) {
//     switchCollection(resourceStatus.getUpdated());
//     thisCollection.insertOne(resourceStatusToDocument(environmentName, resourceStatus));
//   }
// 
// 
//   /**
//    * Inserts multiple resource statuses into corresponding month collection
//    * @param environmentName
//    * @param resourcesStatus
//    */
//   public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resourcesStatus) {
//     resourcesStatus.forEach(rs -> {
//       switchCollection(rs.getUpdated());
//       insert(environmentName, rs);
//     });
//   }
// 
// 
//   @Deprecated
//   public List<ResourceStatus> getStatuses(String environmentName, String resourceId, Date from, Date to) {
//     // consider month switch during data extraction if will be used
//     switchCollection(from);
// 
//     return thisCollection.find(and(
//         eq("environmentName", environmentName),
//         gte("updated", from),
//         lte("updated", to),
//         eq("resource.resourceId", resourceId))
//     )
//         .sort(Sorts.ascending("updated"))
//         .map(DocumentMapper::resourceStatusFromDocument)
//         .into(new ArrayList<>());
// 
//   }
// 
//   /**
//    * Fetch time scale statuses for particular resource
//    * @param environmentName environment that resource belongs to
//    * @param resourceId resource id to fetch statuses
//    * @param from start date for statuses fetching
//    * @param to end date for statuses fetching
//    * @return
//    */
//   public List<StatusUpdate> getStatusUpdates(String environmentName, String resourceId, Date from, Date to) {
//     List<Date[]> dateFrames = DataUtils.splitDatesIntoMonths(from, to);
//     List<StatusUpdate> updates = new ArrayList<>();
// 
//     for (Date[] dates : dateFrames) {
//       switchCollection(dates[0]);
// 
//       Bson filter = and(
//           eq("environmentName", environmentName),
//           eq("resource.resourceId", resourceId),
//           gte("updated", dates[0]),
//           lte("updated", dates[1])
//       );
// 
//       Bson project = fields(include("updated", "statusOrdinal"), excludeId());
// 
//       List<StatusUpdate> monthlyUpdates = this.thisCollection
//           .find(filter)
//           .projection(project)
//           .map(
//               doc -> new StatusUpdateImpl(
//                   Status.fromSerialNumber(doc.getInteger("statusOrdinal")),
//                   doc.getDate("updated")
//               )
//           )
//           .into(new ArrayList<>());
// 
//       updates.addAll(monthlyUpdates);
//     }
//     return updates;
// 
//   }
// }


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.ResourceStatusDetailDAO;
import java.util.List;
import java.util.UUID;
package org.yagel.monitor.runner.test.intergation.dao;



public class ResourceStatusDetailDAOTest extends AbstractDAOTest {

  private ResourceStatusDetailDAO monthDetailDAO;

  private String environemntName;

  @BeforeClass
  public void setUp() 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/ResourceStatusDetailDAO.java
// public class ResourceStatusDetailDAO extends AbstractTimeRangeDAO {
// 
//   public ResourceStatusDetailDAO(MongoDatabase mongoDatabase) {
//     super(mongoDatabase);
//     switchCollection(new Date());
//   }
// 
// 
//   /**
//    * Inserts new resource status into corresponding month collection
//    *
//    * @param environmentName environment resource belongs to
//    * @param resourceStatus  status to be inserted
//    */
//   public synchronized void insert(String environmentName, ResourceStatus resourceStatus) {
//     switchCollection(resourceStatus.getUpdated());
//     thisCollection.insertOne(resourceStatusToDocument(environmentName, resourceStatus));
//   }
// 
// 
//   /**
//    * Inserts multiple resource statuses into corresponding month collection
//    * @param environmentName
//    * @param resourcesStatus
//    */
//   public synchronized void insert(final String environmentName, final Collection<ResourceStatus> resourcesStatus) {
//     resourcesStatus.forEach(rs -> {
//       switchCollection(rs.getUpdated());
//       insert(environmentName, rs);
//     });
//   }
// 
// 
//   @Deprecated
//   public List<ResourceStatus> getStatuses(String environmentName, String resourceId, Date from, Date to) {
//     // consider month switch during data extraction if will be used
//     switchCollection(from);
// 
//     return thisCollection.find(and(
//         eq("environmentName", environmentName),
//         gte("updated", from),
//         lte("updated", to),
//         eq("resource.resourceId", resourceId))
//     )
//         .sort(Sorts.ascending("updated"))
//         .map(DocumentMapper::resourceStatusFromDocument)
//         .into(new ArrayList<>());
// 
//   }
// 
//   /**
//    * Fetch time scale statuses for particular resource
//    * @param environmentName environment that resource belongs to
//    * @param resourceId resource id to fetch statuses
//    * @param from start date for statuses fetching
//    * @param to end date for statuses fetching
//    * @return
//    */
//   public List<StatusUpdate> getStatusUpdates(String environmentName, String resourceId, Date from, Date to) {
//     List<Date[]> dateFrames = DataUtils.splitDatesIntoMonths(from, to);
//     List<StatusUpdate> updates = new ArrayList<>();
// 
//     for (Date[] dates : dateFrames) {
//       switchCollection(dates[0]);
// 
//       Bson filter = and(
//           eq("environmentName", environmentName),
//           eq("resource.resourceId", resourceId),
//           gte("updated", dates[0]),
//           lte("updated", dates[1])
//       );
// 
//       Bson project = fields(include("updated", "statusOrdinal"), excludeId());
// 
//       List<StatusUpdate> monthlyUpdates = this.thisCollection
//           .find(filter)
//           .projection(project)
//           .map(
//               doc -> new StatusUpdateImpl(
//                   Status.fromSerialNumber(doc.getInteger("statusOrdinal")),
//                   doc.getDate("updated")
//               )
//           )
//           .into(new ArrayList<>());
// 
//       updates.addAll(monthlyUpdates);
//     }
//     return updates;
// 
//   }
// }


// Path: environment.monitor.runner/src/test/java/org/yagel/monitor/runner/test/intergation/dao/ResourceStatusDetailDAOTest.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.ResourceStatusDetailDAO;
import java.util.List;
import java.util.UUID;

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



public class ResourceStatusDetailDAOTest extends AbstractDAOTest {

  private ResourceStatusDetailDAO monthDetailDAO;

  private String environemntName;

  @BeforeClass
  public void setUp() throws Exception {
    monthDetailDAO = MongoConnector.getInstance().getMonthDetailDAO();