FetchDeployDAO { public List<com.wipro.ats.bdre.md.beans.table.ProcessDeploymentQueue> fetchDeploy(Integer deployNumber) { List<ProcessDeploymentQueue> notStartedPDQList = new ArrayList<ProcessDeploymentQueue>(); List<com.wipro.ats.bdre.md.beans.table.ProcessDeploymentQueue> returnPDQList = new ArrayList<com.wipro.ats.bdre.md.beans.table.ProcessDeploymentQueue>(); Session session = sessionFactory.openSession(); try { session.beginTransaction(); DeployStatus notStartedDeployStatus = new DeployStatus(); notStartedDeployStatus.setDeployStatusId((short) 1); DeployStatus pickedDeployStatus = new DeployStatus(); pickedDeployStatus.setDeployStatusId((short) 5); Criteria checkNotStartedProcesses = session.createCriteria(ProcessDeploymentQueue.class).add(Restrictions.eq("deployStatus", notStartedDeployStatus)); LOGGER.info("Deploy number passed :" + deployNumber); Integer notStartedProcessCount = checkNotStartedProcesses.list().size(); LOGGER.info("Not started process count :" + notStartedProcessCount); if (notStartedProcessCount >= deployNumber) { checkNotStartedProcesses.setMaxResults(deployNumber); } notStartedPDQList = checkNotStartedProcesses.list(); if (notStartedProcessCount != 0) { for (ProcessDeploymentQueue pdq : notStartedPDQList) { pdq.setDeployStatus(pickedDeployStatus); session.update(pdq); } } else { LOGGER.info("Nothing fetched from PDQ to update"); } Criteria checkPickedProcesses = session.createCriteria(ProcessDeploymentQueue.class).add(Restrictions.eq("deployStatus", pickedDeployStatus)); List<ProcessDeploymentQueue> pickedPDQList = new ArrayList<ProcessDeploymentQueue>(); Integer pickedProcessCount = checkPickedProcesses.list().size(); LOGGER.info("Picked process count :" + pickedProcessCount); if (pickedProcessCount >= deployNumber) { checkPickedProcesses.setMaxResults(deployNumber); } pickedPDQList = checkPickedProcesses.list(); for (ProcessDeploymentQueue pickedPDQ : pickedPDQList) { com.wipro.ats.bdre.md.beans.table.ProcessDeploymentQueue returnPDQ = new com.wipro.ats.bdre.md.beans.table.ProcessDeploymentQueue(); returnPDQ.setDeploymentId(pickedPDQ.getDeploymentId()); returnPDQ.setProcessId(pickedPDQ.getProcess().getProcessId()); returnPDQ.setDeployStatusId((int) pickedPDQ.getDeployStatus().getDeployStatusId()); returnPDQ.setBusDomainId(pickedPDQ.getBusDomain().getBusDomainId()); returnPDQ.setProcessTypeId(pickedPDQ.getProcessType().getProcessTypeId()); returnPDQ.setInsertTs(pickedPDQ.getInsertTs()); returnPDQ.setStartTs(pickedPDQ.getStartTs()); returnPDQ.setEndTs(pickedPDQ.getEndTs()); returnPDQ.setDeployScriptLocation(pickedPDQ.getDeployScriptLocation()); returnPDQ.setFetchNum(deployNumber); returnPDQ.setCounter(notStartedProcessCount); returnPDQ.setUserName(pickedPDQ.getUserName()); returnPDQList.add(returnPDQ); } session.getTransaction().commit(); } catch (MetadataException e) { session.getTransaction().rollback(); LOGGER.error("Error occurred", e); } finally { session.close(); } return returnPDQList; }  List<com.wipro.ats.bdre.md.beans.table.ProcessDeploymentQueue> fetchDeploy(Integer deployNumber);  }
@Test public void testFetchDeploy() throws Exception { List<com.wipro.ats.bdre.md.beans.table.ProcessDeploymentQueue> processDeploymentQueues = new ArrayList<com.wipro.ats.bdre.md.beans.table.ProcessDeploymentQueue>(); processDeploymentQueues = fetchDeployDAO.fetchDeploy(1); for (com.wipro.ats.bdre.md.beans.table.ProcessDeploymentQueue pdq : processDeploymentQueues) { LOGGER.info(pdq); } LOGGER.info("The init deploy test executed "); }