public void testInstallAtLocation() throws BundleException, MalformedURLException, IOException { // create disconnected test regions Region r1 = digraph.createRegion(getName() + ".1"); Region r2 = digraph.createRegion(getName() + ".2"); String location = bundleInstaller.getBundleLocation(PP1); Bundle b1 = null; Bundle b2 = null; String l1 = null; String l2 = null; try { URL url = new URL(location); b1 = r1.installBundle(location + ".1", url.openStream()); l1 = b1.getLocation(); b2 = r2.installBundleAtLocation(location + ".2", url.openStream()); l2 = b2.getLocation(); } finally { if (b1 != null) { try { b1.uninstall(); } catch (BundleException e) { // ignore } } if (b2 != null) { try { b2.uninstall(); } catch (BundleException e) { // ignore } } } assertEquals("Wrong location found.", location + ".1#" + r1.getName(), l1); assertEquals("Wrong location found.", location + ".2", l2); }
/** * Returns the {@link Region} with the specified name or null if it doesn't exist within this * {@code Network} * * @param regionName * @return */ public Region lookup(String regionName) { for (Region r : regions) { if (r.getName().equals(regionName)) { return r; } } return null; }
/** Returns the region with the id given, if it exists. Otherwise, returns null. */ public static Region getRegion(String regionName) { for (Region r : getRegions()) { if (r.getName().equals(regionName)) { return r; } } return null; }
@Programmatic public List<String> allNames() { List<Region> regions = listAllRegions(); List<String> names = new ArrayList<String>(); for (Region r : regions) { names.add(r.getName()); } return names; }
@Test public void testRequestTrialApprove() { final MockHttpServletRequest requestStub = super.getRequestStub(); List<ProductVersion> productVersions = new ArrayList<ProductVersion>(); productVersions.add( productVersionDao.findByProductAndName(productDao.findByShortName("EAM"), "EAM-BC-3")); productVersions.add( productVersionDao.findByProductAndName(productDao.findByShortName("XM"), "XM-BC-3")); User user = userDao.findByUsername(testUserName); Region region = regionDao.findById(2L); Locale locale = Locale.US; String comment = "Test comment."; final NullEmailProvider emailProvider = new NullEmailProvider(); trialEmailComponent.setEmailProvider(emailProvider); TrialRequest trialRequest = trialService.requestTrial(requestStub, productVersions, user, region, locale, comment); List<NullEmailProvider.EmailInfo> asyncEmails = emailProvider.getAsyncEmails(); assertEquals("Verify email count", 2, asyncEmails.size()); NullEmailProvider.EmailInfo emailInfo = asyncEmails.get(0); assertEquals( messageProvider.getMessage( StringDefs.MESSAGE_TRIAL_REQUEST_SUBJECT, trialEmailComponent.productNamesStrungForEmail(productVersions)), emailInfo.subject); assertTrue( emailInfo.text.contains( "Products: " + trialEmailComponent.productNamesStrungForEmail(productVersions))); assertTrue(emailInfo.text.contains("User: "******"Comment: " + comment)); assertTrue(emailInfo.text.contains("Region: " + region.getName())); assertEquals(StringDefs.BC_LEADS_EMAIL, emailInfo.address); String done = trialService.approveTrialRequest(requestStub, trialRequest.getRequestKey()); assertEquals("Done", done); try { trialService.deleteTrialRequest(trialRequest.getRequestKey()); fail("Delete should fail, as it has already been deleted."); } catch (DataAccessException dae) { // eat. } }
@Test public void testRequestTrialSize() { final MockHttpServletRequest requestStub = super.getRequestStub(); List<ProductVersion> productVersions = new ArrayList<ProductVersion>(); productVersions.add( productVersionDao.findByProductAndName(productDao.findByShortName("EAM"), "EAM-BC-3")); User user = userDao.findByUsername(testUserName); Region region = regionDao.findById(1L); Locale locale = Locale.US; String comment = "Test comment."; final NullEmailProvider emailProvider = new NullEmailProvider(); trialEmailComponent.setEmailProvider(emailProvider); TrialRequest trialRequest = trialService.requestTrial(requestStub, productVersions, user, region, locale, comment); List<NullEmailProvider.EmailInfo> asyncEmails = emailProvider.getAsyncEmails(); assertEquals(2, asyncEmails.size()); NullEmailProvider.EmailInfo emailInfo = asyncEmails.get(0); assertEquals( messageProvider.getMessage( StringDefs.MESSAGE_TRIAL_REQUEST_SUBJECT, trialEmailComponent.productNamesStrungForEmail(productVersions)), emailInfo.subject); assertTrue( emailInfo.text.contains( "Products: " + trialEmailComponent.productNamesStrungForEmail(productVersions))); assertTrue(emailInfo.text.contains("User: "******"Comment: " + comment)); assertTrue(emailInfo.text.contains("Region: " + region.getName())); logger.debug("\n----- EMAIL BODY --- \n" + emailInfo.text + "\n---------------"); loginAdminUser(); assertEquals(1, trialService.getTrialRequests().size()); trialService.deleteTrialRequest(trialRequest.getRequestKey()); assertEquals(0, trialService.getTrialRequests().size()); }
public String getVacationListByRegionJSON( Date dateFrom, Date dateTo, List<Vacation> vacationList) { List<Region> regionList = regionService.getRegions(); List<Employee> employeeList = new ArrayList<Employee>(); for (Vacation vacation : vacationList) { Employee employee = vacation.getEmployee(); if (!(employeeList.contains(employee))) { employeeList.add(employee); } } final JsonArrayNodeBuilder result = anArrayBuilder(); // для каждого проекта смотрим сотрудников у которых есть отпуск for (Region region : regionList) { JsonArrayNodeBuilder employeeNode = anArrayBuilder(); boolean hasEmployees = false; for (Employee employee : employeeList) { if (employee.getRegion().getId().equals(region.getId())) { JsonArrayNodeBuilder vacationNode = createVacationsNode(employee, vacationList); hasEmployees = true; employeeNode.withElement( anObjectBuilder() .withField("employee", aStringBuilder(employee.getName())) .withField("vacations", vacationNode)); } } if (hasEmployees) { result.withElement( anObjectBuilder() .withField("region_id", aStringBuilder(region.getId().toString())) .withField("region_name", aStringBuilder(region.getName())) .withField("employeeList", employeeNode) .withField("holidays", getHolidayInRegion(dateFrom, dateTo, region))); } } return JsonUtil.format(result); }
@Programmatic public String nameForRegion(Region region) { return (region != null) ? region.getName() : null; }