@Test public void testGetRollingDeploys() throws Exception { int sixMonthDeploy = 2; int fiveMonthDeploy = 3; int fourMonthDeploy = 5; int threeMonthDeploy = 9; int twoMonthDeploy = 7; int oneMonthDeploy = 4; int totalDeploy = totalList( sixMonthDeploy, fiveMonthDeploy, fourMonthDeploy, threeMonthDeploy, twoMonthDeploy, oneMonthDeploy); int[] deployedCountList = new int[] { sixMonthDeploy, fiveMonthDeploy, fourMonthDeploy, threeMonthDeploy, twoMonthDeploy, oneMonthDeploy }; int sixMonthTrial = 5; int fiveMonthTrial = 9; int fourMonthTrial = 4; int threeMonthTrial = 12; int twoMonthTrial = 1; int oneMonthTrial = 8; int totalTrial = totalList( sixMonthTrial, fiveMonthTrial, fourMonthTrial, threeMonthTrial, twoMonthTrial, oneMonthTrial); int[] trialCountList = new int[] { sixMonthTrial, fiveMonthTrial, fourMonthTrial, threeMonthTrial, twoMonthTrial, oneMonthTrial }; assertEquals( "Lengths of trialMonths and deployMonths should be same", trialCountList.length, deployedCountList.length); User user = this.createUser("*****@*****.**", "UberUser", "LastName", "password", Role.ROLE_SALES); userDao.save(user); addAWSCredentials(user); user = userDao.findByUsername("*****@*****.**"); assertNotNull(user); Date now = new Date(); GregorianCalendar cal = new GregorianCalendar(); cal.setTime(now); zeroOutTime(cal); cal.set(GregorianCalendar.DATE, 1); List<Date> datesToDeploy = getDates(cal.getTime(), oneMonthDeploy); List<Date> datesToTry = getDates(cal.getTime(), oneMonthTrial); cal.add(GregorianCalendar.MONTH, -1); datesToDeploy.addAll(getDates(cal.getTime(), twoMonthDeploy)); datesToTry.addAll(getDates(cal.getTime(), twoMonthTrial)); cal.add(GregorianCalendar.MONTH, -1); datesToDeploy.addAll(getDates(cal.getTime(), threeMonthDeploy)); datesToTry.addAll(getDates(cal.getTime(), threeMonthTrial)); cal.add(GregorianCalendar.MONTH, -1); datesToDeploy.addAll(getDates(cal.getTime(), fourMonthDeploy)); datesToTry.addAll(getDates(cal.getTime(), fourMonthTrial)); cal.add(GregorianCalendar.MONTH, -1); datesToDeploy.addAll(getDates(cal.getTime(), fiveMonthDeploy)); datesToTry.addAll(getDates(cal.getTime(), fiveMonthTrial)); cal.add(GregorianCalendar.MONTH, -1); datesToDeploy.addAll(getDates(cal.getTime(), sixMonthDeploy)); datesToTry.addAll(getDates(cal.getTime(), sixMonthTrial)); assertEquals("Trial total dates", totalTrial, datesToTry.size()); assertEquals("Deploy total dates", totalDeploy, datesToDeploy.size()); Region region = regionDao.findById(1L); assertNotNull(region); /* * TRIALS SECTION */ List<Product> productsForTrial = productDao.findByTrialsAvailable(true); ArrayList<Long> validTrialProductIds = new ArrayList<>(); for (Product product : productsForTrial) { ProductVersion productVersion = pickOne(product.getProductVersions(), region, false); if (productVersion == null) { continue; } loginAdminUser(); this.activateTrial("*****@*****.**", product); validTrialProductIds.add(product.getId()); login("*****@*****.**", "password"); for (Date tryDate : datesToTry) { DeployRequestDto deployRequestDto = this.getTrialRequestFor(user, productVersion, region, tryDate); DeploymentStackDto retDto = deploymentService.deployMultipleProducts(getRequestStub(), deployRequestDto); TrialInstance instance = trialInstanceDao.findById(retDto.getId()); assertEquals(instance.getCreatedAt(), tryDate); } } List<Long[]> productAndVersionIdList = this.getDtoProdAndVersionList(productDao.findAll(), region); for (Date deployDate : datesToDeploy) { AmazonCredentials amazonCredentials = amazonCredentialsDao.findByUserAndName(user, "Dummy Key"); assertNotNull(amazonCredentials); loginAdminUser(); activateDeploys(user, productAndVersionIdList); login(user.getUsername(), "password"); DeployRequestDto reqDto = this.getDeployRequestFor( user, productAndVersionIdList, region, amazonCredentials, deployDate); DeploymentStackDto result = deploymentService.deployMultipleProducts(getRequestStub(), reqDto); DeploymentStack stack = deploymentStackDao.findById(result.getId()); assertEquals( "deployDate and stack created at times should be ==", deployDate, stack.getCreatedAt()); } loginAdminUser(); DashboardRollingDto rollingDto = dashboardService.getRollingList(deployedCountList.length); assertEquals( "Confirm correct num of months..", deployedCountList.length, (int) rollingDto.getMonthCount()); int index = 0; for (DashboardRollingPeriodDto period : rollingDto.getRollingDeployments()) { DashboardRollingMonthDto month = (DashboardRollingMonthDto) period; assertEquals("Confirm index position", index + 1, (int) month.getMonth()); assertEquals( "Confirm total deploys for month (index:" + index + "):" + month.getName(), (long) deployedCountList[index], (long) month.getAws()); assertEquals( "Confirm total trials for month (index:" + index + "):" + month.getName(), (long) (trialCountList[index] * validTrialProductIds.size()), (long) month.getInfor24()); index++; } }